Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f7b26686
提交
f7b26686
authored
7月 13, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move convertStringToBytes to StringUtils.
上级
39baefe5
隐藏空白字符变更
内嵌
并排
正在显示
27 个修改的文件
包含
118 行增加
和
119 行删除
+118
-119
changelog.html
h2/src/docsrc/html/changelog.html
+3
-1
Parser.java
h2/src/main/org/h2/command/Parser.java
+1
-2
AlterUser.java
h2/src/main/org/h2/command/ddl/AlterUser.java
+2
-2
CreateUser.java
h2/src/main/org/h2/command/ddl/CreateUser.java
+2
-2
ScriptCommand.java
h2/src/main/org/h2/command/dml/ScriptCommand.java
+1
-1
SessionRemote.java
h2/src/main/org/h2/engine/SessionRemote.java
+1
-1
User.java
h2/src/main/org/h2/engine/User.java
+2
-2
FullText.java
h2/src/main/org/h2/fulltext/FullText.java
+1
-2
JdbcXAConnection.java
h2/src/main/org/h2/jdbcx/JdbcXAConnection.java
+2
-3
JdbcXid.java
h2/src/main/org/h2/jdbcx/JdbcXid.java
+5
-5
TraceObject.java
h2/src/main/org/h2/message/TraceObject.java
+1
-2
CipherFactory.java
h2/src/main/org/h2/security/CipherFactory.java
+3
-2
WebServer.java
h2/src/main/org/h2/server/web/WebServer.java
+2
-1
FileLock.java
h2/src/main/org/h2/store/FileLock.java
+2
-2
FileSystem.java
h2/src/main/org/h2/store/fs/FileSystem.java
+2
-2
Recover.java
h2/src/main/org/h2/tools/Recover.java
+3
-2
StringUtils.java
h2/src/main/org/h2/util/StringUtils.java
+61
-0
Utils.java
h2/src/main/org/h2/util/Utils.java
+0
-62
Value.java
h2/src/main/org/h2/value/Value.java
+3
-4
ValueBytes.java
h2/src/main/org/h2/value/ValueBytes.java
+2
-1
ValueLob.java
h2/src/main/org/h2/value/ValueLob.java
+2
-2
ValueLobDb.java
h2/src/main/org/h2/value/ValueLobDb.java
+2
-2
ValueUuid.java
h2/src/main/org/h2/value/ValueUuid.java
+1
-1
TestCsv.java
h2/src/test/org/h2/test/db/TestCsv.java
+1
-2
TestSecurity.java
h2/src/test/org/h2/test/unit/TestSecurity.java
+4
-3
TestStringUtils.java
h2/src/test/org/h2/test/unit/TestStringUtils.java
+6
-7
SecureKeyStoreBuilder.java
h2/src/tools/org/h2/dev/security/SecureKeyStoreBuilder.java
+3
-3
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
f7b26686
...
...
@@ -18,7 +18,9 @@ Change Log
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
Memory mapped files: There was a bug in version 1.2.139 so that memory mapped files
<ul><li>
Primary key violations threw a strange exception message when using a single column INT or BIGINT key.
</li><li>
EXPLAIN ANALYZE now also lists the number of pages read from the file.
</li><li>
Memory mapped files: There was a bug in version 1.2.139 so that memory mapped files
could only be used together with split, for example: split:nioMapped: - the problem is now solved.
It is still a good idea to use split:nioMapped: to work around the 2 GB limitation of memory mapped files.
</li><li>
Memory mapped files: the system property h2.nioCleanerHack is now disabled by default
...
...
h2/src/main/org/h2/command/Parser.java
浏览文件 @
f7b26686
...
...
@@ -127,7 +127,6 @@ import org.h2.table.Table;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableView
;
import
org.h2.table.TableFilter.TableFilterVisitor
;
import
org.h2.util.Utils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.New
;
import
org.h2.util.StatementBuilder
;
...
...
@@ -2321,7 +2320,7 @@ public class Parser {
read
();
if
(
equalsToken
(
"X"
,
name
)
&&
currentTokenType
==
VALUE
&&
currentValue
.
getType
()
==
Value
.
STRING
)
{
read
();
byte
[]
buffer
=
Utils
.
convertStringToBytes
(
currentValue
.
getString
());
byte
[]
buffer
=
String
Utils
.
convertStringToBytes
(
currentValue
.
getString
());
r
=
ValueExpression
.
get
(
ValueBytes
.
getNoCopy
(
buffer
));
}
else
if
(
readIf
(
"."
))
{
r
=
readTermObjectDot
(
name
);
...
...
h2/src/main/org/h2/command/ddl/AlterUser.java
浏览文件 @
f7b26686
...
...
@@ -13,7 +13,7 @@ import org.h2.engine.User;
import
org.h2.expression.Expression
;
import
org.h2.message.DbException
;
import
org.h2.security.SHA256
;
import
org.h2.util.Utils
;
import
org.h2.util.
String
Utils
;
/**
* This class represents the statements
...
...
@@ -83,7 +83,7 @@ public class AlterUser extends DefineCommand {
}
private
byte
[]
getByteArray
(
Expression
e
)
{
return
Utils
.
convertStringToBytes
(
e
.
optimize
(
session
).
getValue
(
session
).
getString
());
return
String
Utils
.
convertStringToBytes
(
e
.
optimize
(
session
).
getValue
(
session
).
getString
());
}
public
int
update
()
{
...
...
h2/src/main/org/h2/command/ddl/CreateUser.java
浏览文件 @
f7b26686
...
...
@@ -13,7 +13,7 @@ import org.h2.engine.User;
import
org.h2.expression.Expression
;
import
org.h2.message.DbException
;
import
org.h2.security.SHA256
;
import
org.h2.util.Utils
;
import
org.h2.util.
String
Utils
;
/**
* This class represents the statement
...
...
@@ -50,7 +50,7 @@ public class CreateUser extends DefineCommand {
}
private
byte
[]
getByteArray
(
Expression
e
)
{
return
Utils
.
convertStringToBytes
(
e
.
optimize
(
session
).
getValue
(
session
).
getString
());
return
String
Utils
.
convertStringToBytes
(
e
.
optimize
(
session
).
getValue
(
session
).
getString
());
}
public
int
update
()
{
...
...
h2/src/main/org/h2/command/dml/ScriptCommand.java
浏览文件 @
f7b26686
...
...
@@ -356,7 +356,7 @@ public class ScriptCommand extends ScriptBase {
if
(
len
<=
0
)
{
break
;
}
buff
.
append
(
Utils
.
convertBytesToString
(
bytes
,
len
)).
append
(
"')"
);
buff
.
append
(
String
Utils
.
convertBytesToString
(
bytes
,
len
)).
append
(
"')"
);
String
sql
=
buff
.
toString
();
add
(
sql
,
true
);
}
...
...
h2/src/main/org/h2/engine/SessionRemote.java
浏览文件 @
f7b26686
...
...
@@ -366,7 +366,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
// ignore
}
if
(
clientVersion
>=
Constants
.
TCP_PROTOCOL_VERSION
)
{
sessionId
=
Utils
.
convertBytesToString
(
MathUtils
.
secureRandomBytes
(
32
));
sessionId
=
String
Utils
.
convertBytesToString
(
MathUtils
.
secureRandomBytes
(
32
));
synchronized
(
this
)
{
for
(
Transfer
transfer
:
transferList
)
{
try
{
...
...
h2/src/main/org/h2/engine/User.java
浏览文件 @
f7b26686
...
...
@@ -159,9 +159,9 @@ public class User extends RightOwner {
}
if
(
password
)
{
buff
.
append
(
" SALT '"
).
append
(
Utils
.
convertBytesToString
(
salt
)).
append
(
String
Utils
.
convertBytesToString
(
salt
)).
append
(
"' HASH '"
).
append
(
Utils
.
convertBytesToString
(
passwordHash
)).
append
(
String
Utils
.
convertBytesToString
(
passwordHash
)).
append
(
'\''
);
}
else
{
buff
.
append
(
" PASSWORD ''"
);
...
...
h2/src/main/org/h2/fulltext/FullText.java
浏览文件 @
f7b26686
...
...
@@ -34,7 +34,6 @@ import org.h2.expression.ValueExpression;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.message.DbException
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.Utils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.New
;
...
...
@@ -461,7 +460,7 @@ public class FullText {
case
Types
.
VARBINARY
:
case
Types
.
LONGVARBINARY
:
case
Types
.
BINARY
:
return
"'"
+
Utils
.
convertBytesToString
((
byte
[])
data
)
+
"'"
;
return
"'"
+
String
Utils
.
convertBytesToString
((
byte
[])
data
)
+
"'"
;
case
Types
.
CLOB
:
case
Types
.
JAVA_OBJECT
:
case
Types
.
OTHER
:
...
...
h2/src/main/org/h2/jdbcx/JdbcXAConnection.java
浏览文件 @
f7b26686
...
...
@@ -22,7 +22,6 @@ import javax.transaction.xa.Xid;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.SysProperties
;
import
org.h2.jdbc.JdbcConnection
;
import
org.h2.util.Utils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.New
;
import
org.h2.util.StringUtils
;
...
...
@@ -436,9 +435,9 @@ implements XAConnection, XAResource
buff
.
append
(
"\"f:"
).
append
(
xid
.
getFormatId
()).
append
(
",bq:"
).
append
(
Utils
.
convertBytesToString
(
xid
.
getBranchQualifier
())).
append
(
String
Utils
.
convertBytesToString
(
xid
.
getBranchQualifier
())).
append
(
",gx:"
).
append
(
Utils
.
convertBytesToString
(
xid
.
getGlobalTransactionId
())).
append
(
String
Utils
.
convertBytesToString
(
xid
.
getGlobalTransactionId
())).
append
(
",c:"
).
append
(
xid
.
getClass
().
getName
()).
append
(
"\""
);
...
...
h2/src/main/org/h2/jdbcx/JdbcXid.java
浏览文件 @
f7b26686
...
...
@@ -11,7 +11,7 @@ import javax.transaction.xa.Xid;
import
org.h2.constant.ErrorCode
;
import
org.h2.message.DbException
;
import
org.h2.message.TraceObject
;
import
org.h2.util.Utils
;
import
org.h2.util.
String
Utils
;
/**
* An object of this class represents a transaction id.
...
...
@@ -37,8 +37,8 @@ implements Xid
throw
DbException
.
get
(
ErrorCode
.
WRONG_XID_FORMAT_1
,
tid
);
}
formatId
=
Integer
.
parseInt
(
tokenizer
.
nextToken
());
branchQualifier
=
Utils
.
convertStringToBytes
(
tokenizer
.
nextToken
());
globalTransactionId
=
Utils
.
convertStringToBytes
(
tokenizer
.
nextToken
());
branchQualifier
=
String
Utils
.
convertStringToBytes
(
tokenizer
.
nextToken
());
globalTransactionId
=
String
Utils
.
convertStringToBytes
(
tokenizer
.
nextToken
());
}
catch
(
RuntimeException
e
)
{
throw
DbException
.
get
(
ErrorCode
.
WRONG_XID_FORMAT_1
,
tid
);
}
...
...
@@ -52,9 +52,9 @@ implements Xid
buff
.
append
(
'_'
).
append
(
formatId
).
append
(
'_'
).
append
(
Utils
.
convertBytesToString
(
branchQualifier
)).
append
(
String
Utils
.
convertBytesToString
(
branchQualifier
)).
append
(
'_'
).
append
(
Utils
.
convertBytesToString
(
globalTransactionId
));
append
(
String
Utils
.
convertBytesToString
(
globalTransactionId
));
return
buff
.
toString
();
}
...
...
h2/src/main/org/h2/message/TraceObject.java
浏览文件 @
f7b26686
...
...
@@ -14,7 +14,6 @@ import java.util.ArrayList;
import
java.util.Map
;
import
org.h2.constant.SysProperties
;
import
org.h2.expression.ParameterInterface
;
import
org.h2.util.Utils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
...
...
@@ -326,7 +325,7 @@ public class TraceObject {
if
(
x
==
null
)
{
return
"null"
;
}
return
"org.h2.util.Utils.convertStringToBytes(\""
+
Utils
.
convertBytesToString
(
x
)
+
"\")"
;
return
"org.h2.util.Utils.convertStringToBytes(\""
+
String
Utils
.
convertBytesToString
(
x
)
+
"\")"
;
}
/**
...
...
h2/src/main/org/h2/security/CipherFactory.java
浏览文件 @
f7b26686
...
...
@@ -31,6 +31,7 @@ import org.h2.constant.ErrorCode;
import
org.h2.constant.SysProperties
;
import
org.h2.message.DbException
;
import
org.h2.util.IOUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Utils
;
/**
...
...
@@ -169,13 +170,13 @@ public class CipherFactory {
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
"RSA"
);
store
.
load
(
null
,
password
.
toCharArray
());
PKCS8EncodedKeySpec
keySpec
=
new
PKCS8EncodedKeySpec
(
Utils
.
convertStringToBytes
(
"30820277020100300d06092a864886f70d0101010500048202613082025d02010002818100dc0a13c602b7141110eade2f051b54777b060d0f74e6a110f9cce81159f271ebc88d8e8aa1f743b505fc2e7dfe38d33b8d3f64d1b363d1af4d877833897954cbaec2fa384c22a415498cf306bb07ac09b76b001cd68bf77ea0a628f5101959cf2993a9c23dbee79b19305977f8715ae78d023471194cc900b231eecb0aaea98d02030100010281810099aa4ff4d0a09a5af0bd953cb10c4d08c3d98df565664ac5582e494314d5c3c92dddedd5d316a32a206be4ec084616fe57be15e27cad111aa3c21fa79e32258c6ca8430afc69eddd52d3b751b37da6b6860910b94653192c0db1d02abcfd6ce14c01f238eec7c20bd3bb750940004bacba2880349a9494d10e139ecb2355d101024100ffdc3defd9c05a2d377ef6019fa62b3fbd5b0020a04cc8533bca730e1f6fcf5dfceea1b044fbe17d9eababfbc7d955edad6bc60f9be826ad2c22ba77d19a9f65024100dc28d43fdbbc93852cc3567093157702bc16f156f709fb7db0d9eec028f41fd0edcd17224c866e66be1744141fb724a10fd741c8a96afdd9141b36d67fff6309024077b1cddbde0f69604bdcfe33263fb36ddf24aa3b9922327915b890f8a36648295d0139ecdf68c245652c4489c6257b58744fbdd961834a4cab201801a3b1e52d024100b17142e8991d1b350a0802624759d48ae2b8071a158ff91fabeb6a8f7c328e762143dc726b8529f42b1fab6220d1c676fdc27ba5d44e847c72c52064afd351a902407c6e23fe35bcfcd1a662aa82a2aa725fcece311644d5b6e3894853fd4ce9fe78218c957b1ff03fc9e5ef8ffeb6bd58235f6a215c97d354fdace7e781e4a63e8b"
));
String
Utils
.
convertStringToBytes
(
"30820277020100300d06092a864886f70d0101010500048202613082025d02010002818100dc0a13c602b7141110eade2f051b54777b060d0f74e6a110f9cce81159f271ebc88d8e8aa1f743b505fc2e7dfe38d33b8d3f64d1b363d1af4d877833897954cbaec2fa384c22a415498cf306bb07ac09b76b001cd68bf77ea0a628f5101959cf2993a9c23dbee79b19305977f8715ae78d023471194cc900b231eecb0aaea98d02030100010281810099aa4ff4d0a09a5af0bd953cb10c4d08c3d98df565664ac5582e494314d5c3c92dddedd5d316a32a206be4ec084616fe57be15e27cad111aa3c21fa79e32258c6ca8430afc69eddd52d3b751b37da6b6860910b94653192c0db1d02abcfd6ce14c01f238eec7c20bd3bb750940004bacba2880349a9494d10e139ecb2355d101024100ffdc3defd9c05a2d377ef6019fa62b3fbd5b0020a04cc8533bca730e1f6fcf5dfceea1b044fbe17d9eababfbc7d955edad6bc60f9be826ad2c22ba77d19a9f65024100dc28d43fdbbc93852cc3567093157702bc16f156f709fb7db0d9eec028f41fd0edcd17224c866e66be1744141fb724a10fd741c8a96afdd9141b36d67fff6309024077b1cddbde0f69604bdcfe33263fb36ddf24aa3b9922327915b890f8a36648295d0139ecdf68c245652c4489c6257b58744fbdd961834a4cab201801a3b1e52d024100b17142e8991d1b350a0802624759d48ae2b8071a158ff91fabeb6a8f7c328e762143dc726b8529f42b1fab6220d1c676fdc27ba5d44e847c72c52064afd351a902407c6e23fe35bcfcd1a662aa82a2aa725fcece311644d5b6e3894853fd4ce9fe78218c957b1ff03fc9e5ef8ffeb6bd58235f6a215c97d354fdace7e781e4a63e8b"
));
PrivateKey
privateKey
=
keyFactory
.
generatePrivate
(
keySpec
);
Certificate
[]
certs
=
{
CertificateFactory
.
getInstance
(
"X.509"
)
.
generateCertificate
(
new
ByteArrayInputStream
(
Utils
.
convertStringToBytes
(
"3082018b3081f502044295ce6b300d06092a864886f70d0101040500300d310b3009060355040313024832301e170d3035303532363133323630335a170d3337303933303036353734375a300d310b300906035504031302483230819f300d06092a864886f70d010101050003818d0030818902818100dc0a13c602b7141110eade2f051b54777b060d0f74e6a110f9cce81159f271ebc88d8e8aa1f743b505fc2e7dfe38d33b8d3f64d1b363d1af4d877833897954cbaec2fa384c22a415498cf306bb07ac09b76b001cd68bf77ea0a628f5101959cf2993a9c23dbee79b19305977f8715ae78d023471194cc900b231eecb0aaea98d0203010001300d06092a864886f70d01010405000381810083f4401a279453701bef9a7681a5b8b24f153f7d18c7c892133d97bd5f13736be7505290a445a7d5ceb75522403e5097515cd966ded6351ff60d5193de34cd36e5cb04d380398e66286f99923fd92296645fd4ada45844d194dfd815e6cd57f385c117be982809028bba1116c85740b3d27a55b1a0948bf291ddba44bed337b9"
))),
};
String
Utils
.
convertStringToBytes
(
"3082018b3081f502044295ce6b300d06092a864886f70d0101040500300d310b3009060355040313024832301e170d3035303532363133323630335a170d3337303933303036353734375a300d310b300906035504031302483230819f300d06092a864886f70d010101050003818d0030818902818100dc0a13c602b7141110eade2f051b54777b060d0f74e6a110f9cce81159f271ebc88d8e8aa1f743b505fc2e7dfe38d33b8d3f64d1b363d1af4d877833897954cbaec2fa384c22a415498cf306bb07ac09b76b001cd68bf77ea0a628f5101959cf2993a9c23dbee79b19305977f8715ae78d023471194cc900b231eecb0aaea98d0203010001300d06092a864886f70d01010405000381810083f4401a279453701bef9a7681a5b8b24f153f7d18c7c892133d97bd5f13736be7505290a445a7d5ceb75522403e5097515cd966ded6351ff60d5193de34cd36e5cb04d380398e66286f99923fd92296645fd4ada45844d194dfd815e6cd57f385c117be982809028bba1116c85740b3d27a55b1a0948bf291ddba44bed337b9"
))),
};
store
.
setKeyEntry
(
"h2"
,
privateKey
,
password
.
toCharArray
(),
certs
);
// --- generated code end ---
return
store
;
...
...
h2/src/main/org/h2/server/web/WebServer.java
浏览文件 @
f7b26686
...
...
@@ -31,6 +31,7 @@ import org.h2.engine.Constants;
import
org.h2.message.TraceSystem
;
import
org.h2.server.Service
;
import
org.h2.server.ShutdownHandler
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Utils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.JdbcUtils
;
...
...
@@ -157,7 +158,7 @@ public class WebServer implements Service {
private
String
generateSessionId
()
{
byte
[]
buff
=
MathUtils
.
secureRandomBytes
(
16
);
return
Utils
.
convertBytesToString
(
buff
);
return
String
Utils
.
convertBytesToString
(
buff
);
}
/**
...
...
h2/src/main/org/h2/store/FileLock.java
浏览文件 @
f7b26686
...
...
@@ -22,7 +22,7 @@ import org.h2.message.DbException;
import
org.h2.message.Trace
;
import
org.h2.message.TraceSystem
;
import
org.h2.store.fs.FileSystem
;
import
org.h2.util.Utils
;
import
org.h2.util.
String
Utils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.NetUtils
;
import
org.h2.util.SortedProperties
;
...
...
@@ -288,7 +288,7 @@ public class FileLock implements Runnable {
private
void
setUniqueId
()
{
byte
[]
bytes
=
MathUtils
.
secureRandomBytes
(
RANDOM_BYTES
);
String
random
=
Utils
.
convertBytesToString
(
bytes
);
String
random
=
String
Utils
.
convertBytesToString
(
bytes
);
uniqueId
=
Long
.
toHexString
(
System
.
currentTimeMillis
())
+
random
;
properties
.
setProperty
(
"id"
,
uniqueId
);
}
...
...
h2/src/main/org/h2/store/fs/FileSystem.java
浏览文件 @
f7b26686
...
...
@@ -12,7 +12,7 @@ import java.io.OutputStream;
import
java.util.ArrayList
;
import
org.h2.util.MathUtils
;
import
org.h2.util.New
;
import
org.h2.util.Utils
;
import
org.h2.util.
String
Utils
;
/**
* The file system is a storage abstraction.
...
...
@@ -308,7 +308,7 @@ public abstract class FileSystem {
if
(
newRandom
||
tempRandom
==
null
)
{
byte
[]
prefix
=
new
byte
[
8
];
MathUtils
.
randomBytes
(
prefix
);
tempRandom
=
Utils
.
convertBytesToString
(
prefix
)
+
"."
;
tempRandom
=
String
Utils
.
convertBytesToString
(
prefix
)
+
"."
;
}
return
tempRandom
+
tempSequence
++;
}
...
...
h2/src/main/org/h2/tools/Recover.java
浏览文件 @
f7b26686
...
...
@@ -51,6 +51,7 @@ import org.h2.util.MathUtils;
import
org.h2.util.New
;
import
org.h2.util.SmallLRUCache
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StringUtils
;
import
org.h2.util.TempFileDeleter
;
import
org.h2.util.Tool
;
import
org.h2.util.Utils
;
...
...
@@ -1027,9 +1028,9 @@ public class Recover extends Tool implements DataHandler {
byte
[]
passwordHash
=
sha
.
getHashWithSalt
(
userPasswordHash
,
salt
);
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
"SALT '"
).
append
(
Utils
.
convertBytesToString
(
salt
)).
append
(
String
Utils
.
convertBytesToString
(
salt
)).
append
(
"' HASH '"
).
append
(
Utils
.
convertBytesToString
(
passwordHash
)).
append
(
String
Utils
.
convertBytesToString
(
passwordHash
)).
append
(
'\''
);
byte
[]
replacement
=
buff
.
toString
().
getBytes
();
System
.
arraycopy
(
replacement
,
0
,
s
.
getBytes
(),
saltIndex
,
replacement
.
length
);
...
...
h2/src/main/org/h2/util/StringUtils.java
浏览文件 @
f7b26686
...
...
@@ -21,6 +21,7 @@ import org.h2.message.DbException;
public
class
StringUtils
{
private
static
SoftReference
<
String
[]>
softCache
=
new
SoftReference
<
String
[]>(
null
);
private
static
final
char
[]
HEX
=
"0123456789abcdef"
.
toCharArray
();
private
StringUtils
()
{
// utility class
...
...
@@ -932,4 +933,64 @@ public class StringUtils {
softCache
=
new
SoftReference
<
String
[]>(
null
);
}
/**
* Convert a hex encoded string to a byte array.
*
* @param s the hex encoded string
* @return the byte array
*/
public
static
byte
[]
convertStringToBytes
(
String
s
)
{
int
len
=
s
.
length
();
if
(
len
%
2
!=
0
)
{
throw
DbException
.
get
(
ErrorCode
.
HEX_STRING_ODD_1
,
s
);
}
len
/=
2
;
byte
[]
buff
=
new
byte
[
len
];
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
buff
[
i
]
=
(
byte
)
((
getHexDigit
(
s
,
i
+
i
)
<<
4
)
|
getHexDigit
(
s
,
i
+
i
+
1
));
}
return
buff
;
}
private
static
int
getHexDigit
(
String
s
,
int
i
)
{
char
c
=
s
.
charAt
(
i
);
if
(
c
>=
'0'
&&
c
<=
'9'
)
{
return
c
-
'0'
;
}
else
if
(
c
>=
'a'
&&
c
<=
'f'
)
{
return
c
-
'a'
+
0xa
;
}
else
if
(
c
>=
'A'
&&
c
<=
'F'
)
{
return
c
-
'A'
+
0xa
;
}
else
{
throw
DbException
.
get
(
ErrorCode
.
HEX_STRING_WRONG_1
,
s
);
}
}
/**
* Convert a byte array to a hex encoded string.
*
* @param value the byte array
* @return the hex encoded string
*/
public
static
String
convertBytesToString
(
byte
[]
value
)
{
return
convertBytesToString
(
value
,
value
.
length
);
}
/**
* Convert a byte array to a hex encoded string.
*
* @param value the byte array
* @param len the number of bytes to encode
* @return the hex encoded string
*/
public
static
String
convertBytesToString
(
byte
[]
value
,
int
len
)
{
char
[]
buff
=
new
char
[
len
+
len
];
char
[]
hex
=
HEX
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
c
=
value
[
i
]
&
0xff
;
buff
[
i
+
i
]
=
hex
[
c
>>
4
];
buff
[
i
+
i
+
1
]
=
hex
[
c
&
0xf
];
}
return
new
String
(
buff
);
}
}
h2/src/main/org/h2/util/Utils.java
浏览文件 @
f7b26686
...
...
@@ -46,8 +46,6 @@ public class Utils {
private
static
final
int
GC_DELAY
=
50
;
private
static
final
int
MAX_GC
=
8
;
private
static
final
char
[]
HEX
=
"0123456789abcdef"
.
toCharArray
();
private
static
long
lastGC
;
private
static
final
boolean
ALLOW_ALL_CLASSES
;
...
...
@@ -137,38 +135,6 @@ public class Utils {
return
-
1
;
}
/**
* Convert a hex encoded string to a byte array.
*
* @param s the hex encoded string
* @return the byte array
*/
public
static
byte
[]
convertStringToBytes
(
String
s
)
{
int
len
=
s
.
length
();
if
(
len
%
2
!=
0
)
{
throw
DbException
.
get
(
ErrorCode
.
HEX_STRING_ODD_1
,
s
);
}
len
/=
2
;
byte
[]
buff
=
new
byte
[
len
];
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
buff
[
i
]
=
(
byte
)
((
getHexDigit
(
s
,
i
+
i
)
<<
4
)
|
getHexDigit
(
s
,
i
+
i
+
1
));
}
return
buff
;
}
private
static
int
getHexDigit
(
String
s
,
int
i
)
{
char
c
=
s
.
charAt
(
i
);
if
(
c
>=
'0'
&&
c
<=
'9'
)
{
return
c
-
'0'
;
}
else
if
(
c
>=
'a'
&&
c
<=
'f'
)
{
return
c
-
'a'
+
0xa
;
}
else
if
(
c
>=
'A'
&&
c
<=
'F'
)
{
return
c
-
'A'
+
0xa
;
}
else
{
throw
DbException
.
get
(
ErrorCode
.
HEX_STRING_WRONG_1
,
s
);
}
}
/**
* Calculate the hash code of the given byte array.
*
...
...
@@ -195,34 +161,6 @@ public class Utils {
return
h
;
}
/**
* Convert a byte array to a hex encoded string.
*
* @param value the byte array
* @return the hex encoded string
*/
public
static
String
convertBytesToString
(
byte
[]
value
)
{
return
convertBytesToString
(
value
,
value
.
length
);
}
/**
* Convert a byte array to a hex encoded string.
*
* @param value the byte array
* @param len the number of bytes to encode
* @return the hex encoded string
*/
public
static
String
convertBytesToString
(
byte
[]
value
,
int
len
)
{
char
[]
buff
=
new
char
[
len
+
len
];
char
[]
hex
=
HEX
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
int
c
=
value
[
i
]
&
0xff
;
buff
[
i
+
i
]
=
hex
[
c
>>
4
];
buff
[
i
+
i
+
1
]
=
hex
[
c
&
0xf
];
}
return
new
String
(
buff
);
}
/**
* Compare two byte arrays. This method will always loop over all bytes and
* doesn't use conditional operations in the loop to make sure an attacker
...
...
h2/src/main/org/h2/value/Value.java
浏览文件 @
f7b26686
...
...
@@ -25,7 +25,6 @@ import org.h2.store.LobStorage;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.IOUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Utils
;
/**
* This is the base class for all value classes.
...
...
@@ -751,9 +750,9 @@ public abstract class Value {
case
TIMESTAMP:
return
ValueTimestamp
.
getNoCopy
(
ValueTimestamp
.
parseTimestamp
(
s
.
trim
()));
case
BYTES:
return
ValueBytes
.
getNoCopy
(
Utils
.
convertStringToBytes
(
s
.
trim
()));
return
ValueBytes
.
getNoCopy
(
String
Utils
.
convertStringToBytes
(
s
.
trim
()));
case
JAVA_OBJECT:
return
ValueJavaObject
.
getNoCopy
(
Utils
.
convertStringToBytes
(
s
.
trim
()));
return
ValueJavaObject
.
getNoCopy
(
String
Utils
.
convertStringToBytes
(
s
.
trim
()));
case
STRING:
return
ValueString
.
get
(
s
);
case
STRING_IGNORECASE:
...
...
@@ -767,7 +766,7 @@ public abstract class Value {
case
CLOB:
return
LobStorage
.
createSmallLob
(
CLOB
,
StringUtils
.
utf8Encode
(
s
));
case
BLOB:
return
LobStorage
.
createSmallLob
(
BLOB
,
Utils
.
convertStringToBytes
(
s
.
trim
()));
return
LobStorage
.
createSmallLob
(
BLOB
,
String
Utils
.
convertStringToBytes
(
s
.
trim
()));
case
ARRAY:
return
ValueArray
.
get
(
new
Value
[]{
ValueString
.
get
(
s
)});
case
RESULT_SET:
{
...
...
h2/src/main/org/h2/value/ValueBytes.java
浏览文件 @
f7b26686
...
...
@@ -10,6 +10,7 @@ import java.sql.PreparedStatement;
import
java.sql.SQLException
;
import
org.h2.constant.SysProperties
;
import
org.h2.util.MathUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Utils
;
/**
...
...
@@ -82,7 +83,7 @@ public class ValueBytes extends Value {
}
public
String
getString
()
{
return
Utils
.
convertBytesToString
(
value
);
return
String
Utils
.
convertBytesToString
(
value
);
}
public
long
getPrecision
()
{
...
...
h2/src/main/org/h2/value/ValueLob.java
浏览文件 @
f7b26686
...
...
@@ -538,7 +538,7 @@ public class ValueLob extends Value {
}
else
{
buff
=
IOUtils
.
readBytesAndClose
(
getInputStream
(),
len
);
}
return
Utils
.
convertBytesToString
(
buff
);
return
String
Utils
.
convertBytesToString
(
buff
);
}
catch
(
IOException
e
)
{
throw
DbException
.
convertIOException
(
e
,
fileName
);
}
...
...
@@ -632,7 +632,7 @@ public class ValueLob extends Value {
return
StringUtils
.
quoteStringSQL
(
s
);
}
byte
[]
buff
=
getBytes
();
s
=
Utils
.
convertBytesToString
(
buff
);
s
=
String
Utils
.
convertBytesToString
(
buff
);
return
"X'"
+
s
+
"'"
;
}
...
...
h2/src/main/org/h2/value/ValueLobDb.java
浏览文件 @
f7b26686
...
...
@@ -193,7 +193,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
}
else
{
buff
=
IOUtils
.
readBytesAndClose
(
getInputStream
(),
len
);
}
return
Utils
.
convertBytesToString
(
buff
);
return
String
Utils
.
convertBytesToString
(
buff
);
}
catch
(
IOException
e
)
{
throw
DbException
.
convertIOException
(
e
,
toString
());
}
...
...
@@ -293,7 +293,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
return
StringUtils
.
quoteStringSQL
(
s
);
}
byte
[]
buff
=
getBytes
();
s
=
Utils
.
convertBytesToString
(
buff
);
s
=
String
Utils
.
convertBytesToString
(
buff
);
return
"X'"
+
s
+
"'"
;
}
...
...
h2/src/main/org/h2/value/ValueUuid.java
浏览文件 @
f7b26686
...
...
@@ -64,7 +64,7 @@ public class ValueUuid extends Value {
*/
public
static
ValueUuid
get
(
byte
[]
binary
)
{
if
(
binary
.
length
<
32
)
{
return
get
(
Utils
.
convertBytesToString
(
binary
));
return
get
(
String
Utils
.
convertBytesToString
(
binary
));
}
long
high
=
Utils
.
readLong
(
binary
,
0
);
long
low
=
Utils
.
readLong
(
binary
,
16
);
...
...
h2/src/test/org/h2/test/db/TestCsv.java
浏览文件 @
f7b26686
...
...
@@ -27,7 +27,6 @@ import org.h2.tools.Csv;
import
org.h2.util.IOUtils
;
import
org.h2.util.New
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Utils
;
/**
* CSVREAD and CSVWRITE tests.
...
...
@@ -67,7 +66,7 @@ public class TestCsv extends TestBase {
private
void
testPseudoBom
()
throws
Exception
{
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
// UTF-8 "BOM" / marker
out
.
write
(
Utils
.
convertStringToBytes
(
"ef"
+
"bb"
+
"bf"
));
out
.
write
(
String
Utils
.
convertStringToBytes
(
"ef"
+
"bb"
+
"bf"
));
out
.
write
(
"\"ID\", \"NAME\"\n1, Hello"
.
getBytes
(
"UTF-8"
));
byte
[]
buff
=
out
.
toByteArray
();
Reader
r
=
new
InputStreamReader
(
new
ByteArrayInputStream
(
buff
),
"UTF-8"
);
...
...
h2/src/test/org/h2/test/unit/TestSecurity.java
浏览文件 @
f7b26686
...
...
@@ -10,6 +10,7 @@ import org.h2.security.BlockCipher;
import
org.h2.security.CipherFactory
;
import
org.h2.security.SHA256
;
import
org.h2.test.TestBase
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Utils
;
/**
...
...
@@ -42,7 +43,7 @@ public class TestSecurity extends TestBase {
if
(
data
.
length
>
0
)
{
assertEquals
(
0
,
data
[
0
]);
}
return
Utils
.
convertBytesToString
(
result
);
return
String
Utils
.
convertBytesToString
(
result
);
}
private
void
testOneSHA
(
SHA256
sha
)
{
...
...
@@ -69,7 +70,7 @@ public class TestSecurity extends TestBase {
private
void
checkSHA256
(
String
message
,
String
expected
)
{
SHA256
sha
=
new
SHA256
();
String
hash
=
Utils
.
convertBytesToString
(
sha
.
getHash
(
message
.
getBytes
(),
true
)).
toUpperCase
();
String
hash
=
String
Utils
.
convertBytesToString
(
sha
.
getHash
(
message
.
getBytes
(),
true
)).
toUpperCase
();
assertEquals
(
expected
,
hash
);
}
...
...
@@ -84,7 +85,7 @@ public class TestSecurity extends TestBase {
private
void
testAES
()
{
BlockCipher
test
=
CipherFactory
.
getBlockCipher
(
"AES"
);
test
.
setKey
(
Utils
.
convertStringToBytes
(
"000102030405060708090A0B0C0D0E0F"
));
test
.
setKey
(
String
Utils
.
convertStringToBytes
(
"000102030405060708090A0B0C0D0E0F"
));
byte
[]
in
=
new
byte
[
128
];
byte
[]
enc
=
new
byte
[
128
];
...
...
h2/src/test/org/h2/test/unit/TestStringUtils.java
浏览文件 @
f7b26686
...
...
@@ -15,7 +15,6 @@ import org.h2.message.DbException;
import
org.h2.test.TestBase
;
import
org.h2.util.DateTimeUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Utils
;
/**
* Tests string utility methods.
...
...
@@ -41,18 +40,18 @@ public class TestStringUtils extends TestBase {
}
private
void
testHex
()
{
assertEquals
(
"face"
,
Utils
.
convertBytesToString
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
}));
assertEquals
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
},
Utils
.
convertStringToBytes
(
"face"
));
assertEquals
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
},
Utils
.
convertStringToBytes
(
"fAcE"
));
assertEquals
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
},
Utils
.
convertStringToBytes
(
"FaCe"
));
assertEquals
(
"face"
,
String
Utils
.
convertBytesToString
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
}));
assertEquals
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
},
String
Utils
.
convertStringToBytes
(
"face"
));
assertEquals
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
},
String
Utils
.
convertStringToBytes
(
"fAcE"
));
assertEquals
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
},
String
Utils
.
convertStringToBytes
(
"FaCe"
));
try
{
Utils
.
convertStringToBytes
(
"120"
);
String
Utils
.
convertStringToBytes
(
"120"
);
fail
();
}
catch
(
DbException
e
)
{
assertKnownException
(
DbException
.
toSQLException
(
e
));
}
try
{
Utils
.
convertStringToBytes
(
"fast"
);
String
Utils
.
convertStringToBytes
(
"fast"
);
fail
();
}
catch
(
DbException
e
)
{
assertKnownException
(
DbException
.
toSQLException
(
e
));
...
...
h2/src/tools/org/h2/dev/security/SecureKeyStoreBuilder.java
浏览文件 @
f7b26686
...
...
@@ -16,7 +16,7 @@ import java.security.cert.CertificateEncodingException;
import
java.util.Enumeration
;
import
org.h2.security.CipherFactory
;
import
org.h2.util.Utils
;
import
org.h2.util.
String
Utils
;
/**
* Tool to generate source code for the SecureSocketFactory. First, create a
...
...
@@ -57,14 +57,14 @@ public class SecureKeyStoreBuilder {
System
.
out
.
println
(
"KeyFactory keyFactory = KeyFactory.getInstance(\""
+
key
.
getAlgorithm
()
+
"\");"
);
System
.
out
.
println
(
"store.load(null, password.toCharArray());"
);
String
pkFormat
=
key
.
getFormat
();
String
encoded
=
Utils
.
convertBytesToString
(
key
.
getEncoded
());
String
encoded
=
String
Utils
.
convertBytesToString
(
key
.
getEncoded
());
System
.
out
.
println
(
pkFormat
+
"EncodedKeySpec keySpec = new "
+
pkFormat
+
"EncodedKeySpec(getBytes(\""
+
encoded
+
"\"));"
);
System
.
out
.
println
(
"PrivateKey privateKey = keyFactory.generatePrivate(keySpec);"
);
System
.
out
.
println
(
"Certificate[] certs = {"
);
for
(
Certificate
cert
:
store
.
getCertificateChain
(
alias
))
{
System
.
out
.
println
(
" CertificateFactory.getInstance(\""
+
cert
.
getType
()+
"\")."
);
String
enc
=
Utils
.
convertBytesToString
(
cert
.
getEncoded
());
String
enc
=
String
Utils
.
convertBytesToString
(
cert
.
getEncoded
());
System
.
out
.
println
(
" generateCertificate(new ByteArrayInputStream(getBytes(\""
+
enc
+
"\"))),"
);
// PublicKey pubKey = cert.getPublicKey();
// System.out.println(" pubKey algorithm="+pubKey.getAlgorithm());
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论