Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
051f1ff5
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
051f1ff5
编写于
8月 23, 2011
作者:
B
Brian Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Convert std::sha1 to istrs. Issue #855
上级
bd84fbe9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
35 addition
and
30 deletion
+35
-30
src/comp/back/link.rs
src/comp/back/link.rs
+17
-12
src/lib/sha1.rs
src/lib/sha1.rs
+6
-6
src/test/stdtest/sha1.rs
src/test/stdtest/sha1.rs
+12
-12
未找到文件。
src/comp/back/link.rs
浏览文件 @
051f1ff5
...
...
@@ -6,6 +6,7 @@
import
metadata
::
encoder
;
import
middle
::
trans_common
::
crate_ctxt
;
import
std
::
str
;
import
std
::
istr
;
import
std
::
fs
;
import
std
::
vec
;
import
std
::
option
;
...
...
@@ -314,12 +315,14 @@ fn provided_link_metas(sess: &session::session, c: &ast::crate) ->
// This calculates CMH as defined above
fn
crate_meta_extras_hash
(
sha
:
sha1
,
_
crate
:
&
ast
::
crate
,
metas
:
&
provided_metas
)
->
str
{
fn
len_and_str
(
s
:
&
str
)
->
str
{
ret
#
fmt
[
"%u_%s"
,
str
::
byte_len
(
s
),
s
];
fn
len_and_str
(
s
:
&
istr
)
->
istr
{
ret
istr
::
from_estr
(
#
fmt
[
"%u_%s"
,
istr
::
byte_len
(
s
),
istr
::
to_estr
(
s
)]);
}
fn
len_and_str_lit
(
l
:
&
ast
::
lit
)
->
str
{
ret
len_and_str
(
pprust
::
lit_to_str
(
@
l
));
fn
len_and_str_lit
(
l
:
&
ast
::
lit
)
->
i
str
{
ret
len_and_str
(
istr
::
from_estr
(
pprust
::
lit_to_str
(
@
l
)
));
}
let
cmh_items
=
attr
::
sort_meta_items
(
metas
.cmh_items
);
...
...
@@ -329,10 +332,12 @@ fn len_and_str_lit(l: &ast::lit) -> str {
let
m
=
m_
;
alt
m
.node
{
ast
::
meta_name_value
(
key
,
value
)
{
sha
.input_str
(
len_and_str
(
key
));
sha
.input_str
(
len_and_str
(
istr
::
from_estr
(
key
)
));
sha
.input_str
(
len_and_str_lit
(
value
));
}
ast
::
meta_word
(
name
)
{
sha
.input_str
(
len_and_str
(
name
));
}
ast
::
meta_word
(
name
)
{
sha
.input_str
(
len_and_str
(
istr
::
from_estr
(
name
)));
}
ast
::
meta_list
(
_
,
_
)
{
// FIXME (#607): Implement this
fail
"unimplemented meta_item variant"
;
...
...
@@ -387,7 +392,7 @@ fn crate_meta_vers(sess: &session::session, _crate: &ast::crate,
}
fn
truncated_sha1_result
(
sha
:
sha1
)
->
str
{
ret
str
::
substr
(
sha
.result_str
(),
0u
,
16u
);
ret
istr
::
to_estr
(
istr
::
substr
(
sha
.result_str
(),
0u
,
16u
)
);
}
...
...
@@ -398,12 +403,12 @@ fn symbol_hash(tcx: ty::ctxt, sha: sha1, t: ty::t, link_meta: &link_meta) ->
// to be independent of one another in the crate.
sha
.reset
();
sha
.input_str
(
link_meta
.name
);
sha
.input_str
(
"-"
);
sha
.input_str
(
istr
::
from_estr
(
link_meta
.name
)
);
sha
.input_str
(
~
"-"
);
// FIXME: This wants to be link_meta.meta_hash
sha
.input_str
(
link_meta
.name
);
sha
.input_str
(
"-"
);
sha
.input_str
(
encoder
::
encoded_ty
(
tcx
,
t
));
sha
.input_str
(
istr
::
from_estr
(
link_meta
.name
)
);
sha
.input_str
(
~
"-"
);
sha
.input_str
(
istr
::
from_estr
(
encoder
::
encoded_ty
(
tcx
,
t
)
));
let
hash
=
truncated_sha1_result
(
sha
);
// Prefix with _ so that it never blends into adjacent digits
...
...
src/lib/sha1.rs
浏览文件 @
051f1ff5
...
...
@@ -10,12 +10,12 @@
// Provide message input as bytes
fn
input
(
&
[
u8
]);
// Provide message input as string
fn
input_str
(
&
str
);
fn
input_str
(
&
i
str
);
// Read the digest as a vector of 20 bytes. After calling this no further
// input may provided until reset is called
fn
result
()
->
[
u8
];
// Same as above, just a hex-string version.
fn
result_str
()
->
str
;
fn
result_str
()
->
i
str
;
// Reset the sha1 state for reuse. This is called
// automatically during construction
fn
reset
();
...
...
@@ -215,13 +215,13 @@ fn reset() {
st
.computed
=
false
;
}
fn
input
(
msg
:
&
[
u8
])
{
add_input
(
st
,
msg
);
}
fn
input_str
(
msg
:
&
str
)
{
add_input
(
st
,
str
::
bytes
(
msg
));
}
fn
input_str
(
msg
:
&
istr
)
{
add_input
(
st
,
i
str
::
bytes
(
msg
));
}
fn
result
()
->
[
u8
]
{
ret
mk_result
(
st
);
}
fn
result_str
()
->
str
{
fn
result_str
()
->
i
str
{
let
r
=
mk_result
(
st
);
let
s
=
""
;
let
s
=
~
""
;
for
b
:
u8
in
r
{
s
+=
istr
::
to_estr
(
uint
::
to_str
(
b
as
uint
,
16u
)
);
s
+=
uint
::
to_str
(
b
as
uint
,
16u
);
}
ret
s
;
}
...
...
src/test/stdtest/sha1.rs
浏览文件 @
051f1ff5
...
...
@@ -5,28 +5,28 @@
use
std
;
import
std
::
sha1
;
import
std
::
vec
;
import
std
::
str
;
import
std
::
i
str
;
#[test]
fn
test
()
{
type
test
=
{
input
:
str
,
output
:
[
u8
]};
type
test
=
{
input
:
i
str
,
output
:
[
u8
]};
fn
a_million_letter_a
()
->
str
{
fn
a_million_letter_a
()
->
i
str
{
let
i
=
0
;
let
rs
=
""
;
while
i
<
100000
{
rs
+=
"aaaaaaaaaa"
;
i
+=
1
;
}
let
rs
=
~
""
;
while
i
<
100000
{
rs
+=
~
"aaaaaaaaaa"
;
i
+=
1
;
}
ret
rs
;
}
// Test messages from FIPS 180-1
let
fips_180_1_tests
:
[
test
]
=
[{
input
:
"abc"
,
[{
input
:
~
"abc"
,
output
:
[
0xA9u8
,
0x99u8
,
0x3Eu8
,
0x36u8
,
0x47u8
,
0x06u8
,
0x81u8
,
0x6Au8
,
0xBAu8
,
0x3Eu8
,
0x25u8
,
0x71u8
,
0x78u8
,
0x50u8
,
0xC2u8
,
0x6Cu8
,
0x9Cu8
,
0xD0u8
,
0xD8u8
,
0x9Du8
]},
{
input
:
"abcdbcdecdefdefgefghfghighij"
+
"hijkijkljklmklmnlmnomnopnopq"
,
{
input
:
~
"abcdbcdecdefdefgefghfghighij"
+
~
"hijkijkljklmklmnlmnomnopnopq"
,
output
:
[
0x84u8
,
0x98u8
,
0x3Eu8
,
0x44u8
,
0x1Cu8
,
0x3Bu8
,
0xD2u8
,
0x6Eu8
,
0xBAu8
,
0xAEu8
,
0x4Au8
,
0xA1u8
,
0xF9u8
,
0x51u8
,
0x29u8
,
0xE5u8
,
...
...
@@ -39,12 +39,12 @@ fn a_million_letter_a() -> str {
// Examples from wikipedia
let
wikipedia_tests
:
[
test
]
=
[{
input
:
"The quick brown fox jumps over the lazy dog"
,
[{
input
:
~
"The quick brown fox jumps over the lazy dog"
,
output
:
[
0x2fu8
,
0xd4u8
,
0xe1u8
,
0xc6u8
,
0x7au8
,
0x2du8
,
0x28u8
,
0xfcu8
,
0xedu8
,
0x84u8
,
0x9eu8
,
0xe1u8
,
0xbbu8
,
0x76u8
,
0xe7u8
,
0x39u8
,
0x1bu8
,
0x93u8
,
0xebu8
,
0x12u8
]},
{
input
:
"The quick brown fox jumps over the lazy cog"
,
{
input
:
~
"The quick brown fox jumps over the lazy cog"
,
output
:
[
0xdeu8
,
0x9fu8
,
0x2cu8
,
0x7fu8
,
0xd2u8
,
0x5eu8
,
0x1bu8
,
0x3au8
,
0xfau8
,
0xd3u8
,
0xe8u8
,
0x5au8
,
0x0bu8
,
0xd1u8
,
0x7du8
,
0x9bu8
,
...
...
@@ -74,11 +74,11 @@ fn check_vec_eq(v0: &[u8], v1: &[u8]) {
// Test that it works when accepting the message in pieces
for
t
:
test
in
tests
{
let
len
=
str
::
byte_len
(
t
.input
);
let
len
=
i
str
::
byte_len
(
t
.input
);
let
left
=
len
;
while
left
>
0u
{
let
take
=
(
left
+
1u
)
/
2u
;
sh
.input_str
(
str
::
substr
(
t
.input
,
len
-
left
,
take
));
sh
.input_str
(
i
str
::
substr
(
t
.input
,
len
-
left
,
take
));
left
=
left
-
take
;
}
let
out
=
sh
.result
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录