Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
0de379fd
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,发现更多精彩内容 >>
提交
0de379fd
编写于
8月 25, 2012
作者:
B
Brian Anderson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3282 from killerswan/modes5
Removing more deprecated modes
上级
ed1ab9a5
4f326dd6
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
50 addition
and
38 deletion
+50
-38
src/libstd/md4.rs
src/libstd/md4.rs
+7
-4
src/libstd/sha1.rs
src/libstd/sha1.rs
+39
-33
src/libstd/timer.rs
src/libstd/timer.rs
+4
-1
未找到文件。
src/libstd/md4.rs
浏览文件 @
0de379fd
fn
md4
(
msg
:
~
[
u8
])
->
{
a
:
u32
,
b
:
u32
,
c
:
u32
,
d
:
u32
}
{
#[forbid(deprecated_mode)]
;
#[forbid(deprecated_pattern)]
;
fn
md4
(
msg
:
&
[
u8
])
->
{
a
:
u32
,
b
:
u32
,
c
:
u32
,
d
:
u32
}
{
// subtle: if orig_len is merely uint, then the code below
// subtle: if orig_len is merely uint, then the code below
// which performs shifts by 32 bits or more has undefined
// which performs shifts by 32 bits or more has undefined
// results.
// results.
let
orig_len
:
u64
=
(
vec
::
len
(
msg
)
*
8u
)
as
u64
;
let
orig_len
:
u64
=
(
vec
::
len
(
msg
)
*
8u
)
as
u64
;
// pad message
// pad message
let
mut
msg
=
vec
::
append
(
msg
,
~
[
0x80u8
]);
let
mut
msg
=
vec
::
append
(
vec
::
from_slice
(
msg
)
,
~
[
0x80u8
]);
let
mut
bitlen
=
orig_len
+
8u64
;
let
mut
bitlen
=
orig_len
+
8u64
;
while
(
bitlen
+
64u64
)
%
512u64
>
0u64
{
while
(
bitlen
+
64u64
)
%
512u64
>
0u64
{
vec
::
push
(
msg
,
0u8
);
vec
::
push
(
msg
,
0u8
);
...
@@ -82,7 +85,7 @@ fn rot(r: int, x: u32) -> u32 {
...
@@ -82,7 +85,7 @@ fn rot(r: int, x: u32) -> u32 {
return
{
a
:
a
,
b
:
b
,
c
:
c
,
d
:
d
};
return
{
a
:
a
,
b
:
b
,
c
:
c
,
d
:
d
};
}
}
fn
md4_str
(
msg
:
~
[
u8
])
->
~
str
{
fn
md4_str
(
msg
:
&
[
u8
])
->
~
str
{
let
{
a
,
b
,
c
,
d
}
=
md4
(
msg
);
let
{
a
,
b
,
c
,
d
}
=
md4
(
msg
);
fn
app
(
a
:
u32
,
b
:
u32
,
c
:
u32
,
d
:
u32
,
f
:
fn
(
u32
))
{
fn
app
(
a
:
u32
,
b
:
u32
,
c
:
u32
,
d
:
u32
,
f
:
fn
(
u32
))
{
f
(
a
);
f
(
b
);
f
(
c
);
f
(
d
);
f
(
a
);
f
(
b
);
f
(
c
);
f
(
d
);
...
@@ -100,7 +103,7 @@ fn app(a: u32, b: u32, c: u32, d: u32, f: fn(u32)) {
...
@@ -100,7 +103,7 @@ fn app(a: u32, b: u32, c: u32, d: u32, f: fn(u32)) {
result
result
}
}
fn
md4_text
(
msg
:
~
str
)
->
~
str
{
md4_str
(
str
::
to_bytes
(
msg
))
}
fn
md4_text
(
msg
:
&
str
)
->
~
str
{
md4_str
(
str
::
to_bytes
(
msg
))
}
#[test]
#[test]
fn
test_md4
()
{
fn
test_md4
()
{
...
...
src/libstd/sha1.rs
浏览文件 @
0de379fd
...
@@ -12,6 +12,9 @@
...
@@ -12,6 +12,9 @@
* the `reset` method.
* the `reset` method.
*/
*/
#[forbid(deprecated_mode)]
;
#[forbid(deprecated_pattern)]
;
/*
/*
* A SHA-1 implementation derived from Paul E. Jones's reference
* A SHA-1 implementation derived from Paul E. Jones's reference
* implementation, which is written for clarity, not speed. At some
* implementation, which is written for clarity, not speed. At some
...
@@ -22,9 +25,9 @@
...
@@ -22,9 +25,9 @@
/// The SHA-1 interface
/// The SHA-1 interface
trait
sha1
{
trait
sha1
{
/// Provide message input as bytes
/// Provide message input as bytes
fn
input
(
~
[
u8
]
);
fn
input
(
(
&
[
u8
])
);
/// Provide message input as string
/// Provide message input as string
fn
input_str
(
~
str
);
fn
input_str
(
(
&
str
)
);
/**
/**
* Read the digest as a vector of 20 bytes. After calling this no further
* Read the digest as a vector of 20 bytes. After calling this no further
* input may be provided until reset is called.
* input may be provided until reset is called.
...
@@ -60,7 +63,7 @@ fn sha1() -> sha1 {
...
@@ -60,7 +63,7 @@ fn sha1() -> sha1 {
mut
computed
:
bool
,
mut
computed
:
bool
,
work_buf
:
@~
[
mut
u32
]};
work_buf
:
@~
[
mut
u32
]};
fn
add_input
(
st
:
sha1state
,
msg
:
~
[
u8
])
{
fn
add_input
(
st
:
&
sha1state
,
msg
:
&
[
u8
])
{
assert
(
!
st
.computed
);
assert
(
!
st
.computed
);
for
vec
::
each
(
msg
)
|
element
|
{
for
vec
::
each
(
msg
)
|
element
|
{
st
.msg_block
[
st
.msg_block_idx
]
=
element
;
st
.msg_block
[
st
.msg_block_idx
]
=
element
;
...
@@ -76,7 +79,7 @@ fn add_input(st: sha1state, msg: ~[u8]) {
...
@@ -76,7 +79,7 @@ fn add_input(st: sha1state, msg: ~[u8]) {
if
st
.msg_block_idx
==
msg_block_len
{
process_msg_block
(
st
);
}
if
st
.msg_block_idx
==
msg_block_len
{
process_msg_block
(
st
);
}
}
}
}
}
fn
process_msg_block
(
st
:
sha1state
)
{
fn
process_msg_block
(
st
:
&
sha1state
)
{
assert
(
vec
::
len
(
st
.h
)
==
digest_buf_len
);
assert
(
vec
::
len
(
st
.h
)
==
digest_buf_len
);
assert
(
vec
::
len
(
*
st
.work_buf
)
==
work_buf_len
);
assert
(
vec
::
len
(
*
st
.work_buf
)
==
work_buf_len
);
let
mut
t
:
int
;
// Loop counter
let
mut
t
:
int
;
// Loop counter
...
@@ -155,10 +158,10 @@ fn process_msg_block(st: sha1state) {
...
@@ -155,10 +158,10 @@ fn process_msg_block(st: sha1state) {
fn
circular_shift
(
bits
:
u32
,
word
:
u32
)
->
u32
{
fn
circular_shift
(
bits
:
u32
,
word
:
u32
)
->
u32
{
return
word
<<
bits
|
word
>>
32u32
-
bits
;
return
word
<<
bits
|
word
>>
32u32
-
bits
;
}
}
fn
mk_result
(
st
:
sha1state
)
->
~
[
u8
]
{
fn
mk_result
(
st
:
&
sha1state
)
->
~
[
u8
]
{
if
!
st
.computed
{
pad_msg
(
st
);
st
.computed
=
true
;
}
if
!
(
*
st
)
.computed
{
pad_msg
(
st
);
(
*
st
)
.computed
=
true
;
}
let
mut
rs
:
~
[
u8
]
=
~
[];
let
mut
rs
:
~
[
u8
]
=
~
[];
for
vec
::
each_mut
(
st
.h
)
|
ptr_hpart
|
{
for
vec
::
each_mut
(
(
*
st
)
.h
)
|
ptr_hpart
|
{
let
hpart
=
*
ptr_hpart
;
let
hpart
=
*
ptr_hpart
;
let
a
=
(
hpart
>>
24u32
&
0xFFu32
)
as
u8
;
let
a
=
(
hpart
>>
24u32
&
0xFFu32
)
as
u8
;
let
b
=
(
hpart
>>
16u32
&
0xFFu32
)
as
u8
;
let
b
=
(
hpart
>>
16u32
&
0xFFu32
)
as
u8
;
...
@@ -178,40 +181,40 @@ fn mk_result(st: sha1state) -> ~[u8] {
...
@@ -178,40 +181,40 @@ fn mk_result(st: sha1state) -> ~[u8] {
* call process_msg_block() appropriately. When it returns, it
* call process_msg_block() appropriately. When it returns, it
* can be assumed that the message digest has been computed.
* can be assumed that the message digest has been computed.
*/
*/
fn
pad_msg
(
st
:
sha1state
)
{
fn
pad_msg
(
st
:
&
sha1state
)
{
assert
(
vec
::
len
(
st
.msg_block
)
==
msg_block_len
);
assert
(
vec
::
len
(
(
*
st
)
.msg_block
)
==
msg_block_len
);
/*
/*
* Check to see if the current message block is too small to hold
* Check to see if the current message block is too small to hold
* the initial padding bits and length. If so, we will pad the
* the initial padding bits and length. If so, we will pad the
* block, process it, and then continue padding into a second block.
* block, process it, and then continue padding into a second block.
*/
*/
if
st
.msg_block_idx
>
55u
{
if
(
*
st
)
.msg_block_idx
>
55u
{
st
.msg_block
[
st
.msg_block_idx
]
=
0x80u8
;
(
*
st
)
.msg_block
[(
*
st
)
.msg_block_idx
]
=
0x80u8
;
st
.msg_block_idx
+=
1u
;
(
*
st
)
.msg_block_idx
+=
1u
;
while
st
.msg_block_idx
<
msg_block_len
{
while
(
*
st
)
.msg_block_idx
<
msg_block_len
{
st
.msg_block
[
st
.msg_block_idx
]
=
0u8
;
(
*
st
)
.msg_block
[(
*
st
)
.msg_block_idx
]
=
0u8
;
st
.msg_block_idx
+=
1u
;
(
*
st
)
.msg_block_idx
+=
1u
;
}
}
process_msg_block
(
st
);
process_msg_block
(
st
);
}
else
{
}
else
{
st
.msg_block
[
st
.msg_block_idx
]
=
0x80u8
;
(
*
st
)
.msg_block
[(
*
st
)
.msg_block_idx
]
=
0x80u8
;
st
.msg_block_idx
+=
1u
;
(
*
st
)
.msg_block_idx
+=
1u
;
}
}
while
st
.msg_block_idx
<
56u
{
while
(
*
st
)
.msg_block_idx
<
56u
{
st
.msg_block
[
st
.msg_block_idx
]
=
0u8
;
(
*
st
)
.msg_block
[(
*
st
)
.msg_block_idx
]
=
0u8
;
st
.msg_block_idx
+=
1u
;
(
*
st
)
.msg_block_idx
+=
1u
;
}
}
// Store the message length as the last 8 octets
// Store the message length as the last 8 octets
st
.msg_block
[
56
]
=
(
st
.len_high
>>
24u32
&
0xFFu32
)
as
u8
;
(
*
st
)
.msg_block
[
56
]
=
((
*
st
)
.len_high
>>
24u32
&
0xFFu32
)
as
u8
;
st
.msg_block
[
57
]
=
(
st
.len_high
>>
16u32
&
0xFFu32
)
as
u8
;
(
*
st
)
.msg_block
[
57
]
=
((
*
st
)
.len_high
>>
16u32
&
0xFFu32
)
as
u8
;
st
.msg_block
[
58
]
=
(
st
.len_high
>>
8u32
&
0xFFu32
)
as
u8
;
(
*
st
)
.msg_block
[
58
]
=
((
*
st
)
.len_high
>>
8u32
&
0xFFu32
)
as
u8
;
st
.msg_block
[
59
]
=
(
st
.len_high
&
0xFFu32
)
as
u8
;
(
*
st
)
.msg_block
[
59
]
=
((
*
st
)
.len_high
&
0xFFu32
)
as
u8
;
st
.msg_block
[
60
]
=
(
st
.len_low
>>
24u32
&
0xFFu32
)
as
u8
;
(
*
st
)
.msg_block
[
60
]
=
((
*
st
)
.len_low
>>
24u32
&
0xFFu32
)
as
u8
;
st
.msg_block
[
61
]
=
(
st
.len_low
>>
16u32
&
0xFFu32
)
as
u8
;
(
*
st
)
.msg_block
[
61
]
=
((
*
st
)
.len_low
>>
16u32
&
0xFFu32
)
as
u8
;
st
.msg_block
[
62
]
=
(
st
.len_low
>>
8u32
&
0xFFu32
)
as
u8
;
(
*
st
)
.msg_block
[
62
]
=
((
*
st
)
.len_low
>>
8u32
&
0xFFu32
)
as
u8
;
st
.msg_block
[
63
]
=
(
st
.len_low
&
0xFFu32
)
as
u8
;
(
*
st
)
.msg_block
[
63
]
=
((
*
st
)
.len_low
&
0xFFu32
)
as
u8
;
process_msg_block
(
st
);
process_msg_block
(
st
);
}
}
...
@@ -228,13 +231,16 @@ fn reset() {
...
@@ -228,13 +231,16 @@ fn reset() {
self
.h
[
4
]
=
0xC3D2E1F0u32
;
self
.h
[
4
]
=
0xC3D2E1F0u32
;
self
.computed
=
false
;
self
.computed
=
false
;
}
}
fn
input
(
msg
:
~
[
u8
])
{
add_input
(
self
,
msg
);
}
fn
input
(
msg
:
&
[
u8
])
{
add_input
(
&
self
,
msg
);
}
fn
input_str
(
msg
:
~
str
)
{
add_input
(
self
,
str
::
to_bytes
(
msg
));
}
fn
input_str
(
msg
:
&
str
)
{
fn
result
()
->
~
[
u8
]
{
return
mk_result
(
self
);
}
let
bs
=
str
::
to_bytes
(
msg
);
add_input
(
&
self
,
bs
);
}
fn
result
()
->
~
[
u8
]
{
return
mk_result
(
&
self
);
}
fn
result_str
()
->
~
str
{
fn
result_str
()
->
~
str
{
let
r
=
mk_result
(
self
);
let
r
r
=
mk_result
(
&
self
);
let
mut
s
=
~
""
;
let
mut
s
=
~
""
;
for
vec
::
each
(
r
)
|
b
|
{
s
+=
uint
::
to_str
(
b
as
uint
,
16u
);
}
for
vec
::
each
(
r
r
)
|
b
|
{
s
+=
uint
::
to_str
(
b
as
uint
,
16u
);
}
return
s
;
return
s
;
}
}
}
}
...
...
src/libstd/timer.rs
浏览文件 @
0de379fd
//! Utilities that leverage libuv's `uv_timer_*` API
//! Utilities that leverage libuv's `uv_timer_*` API
#[forbid(deprecated_mode)]
;
#[forbid(deprecated_pattern)]
;
import
uv
=
uv
;
import
uv
=
uv
;
import
uv
::
iotask
;
import
uv
::
iotask
;
import
iotask
::
iotask
;
import
iotask
::
iotask
;
...
@@ -24,7 +27,7 @@
...
@@ -24,7 +27,7 @@
* * val - a value of type T to send over the provided `ch`
* * val - a value of type T to send over the provided `ch`
*/
*/
fn
delayed_send
<
T
:
copy
send
>
(
iotask
:
iotask
,
fn
delayed_send
<
T
:
copy
send
>
(
iotask
:
iotask
,
msecs
:
uint
,
ch
:
comm
::
Chan
<
T
>
,
val
:
T
)
{
msecs
:
uint
,
ch
:
comm
::
Chan
<
T
>
,
+
val
:
T
)
{
unsafe
{
unsafe
{
let
timer_done_po
=
core
::
comm
::
port
::
<
()
>
();
let
timer_done_po
=
core
::
comm
::
port
::
<
()
>
();
let
timer_done_ch
=
core
::
comm
::
chan
(
timer_done_po
);
let
timer_done_ch
=
core
::
comm
::
chan
(
timer_done_po
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录