Skip to content

Removing more deprecated modes #3282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 26, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/libstd/md4.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
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
// which performs shifts by 32 bits or more has undefined
// results.
let orig_len: u64 = (vec::len(msg) * 8u) as u64;

// 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;
while (bitlen + 64u64) % 512u64 > 0u64 {
vec::push(msg, 0u8);
Expand Down Expand Up @@ -82,7 +85,7 @@ fn md4(msg: ~[u8]) -> {a: u32, b: u32, c: u32, d: u32} {
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);
fn app(a: u32, b: u32, c: u32, d: u32, f: fn(u32)) {
f(a); f(b); f(c); f(d);
Expand All @@ -100,7 +103,7 @@ fn md4_str(msg: ~[u8]) -> ~str {
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]
fn test_md4() {
Expand Down
72 changes: 39 additions & 33 deletions src/libstd/sha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
* the `reset` method.
*/

#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];

/*
* A SHA-1 implementation derived from Paul E. Jones's reference
* implementation, which is written for clarity, not speed. At some
Expand All @@ -22,9 +25,9 @@ export sha1;
/// The SHA-1 interface
trait sha1 {
/// Provide message input as bytes
fn input(~[u8]);
fn input((&[u8]));
/// 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
* input may be provided until reset is called.
Expand Down Expand Up @@ -60,7 +63,7 @@ fn sha1() -> sha1 {
mut computed: bool,
work_buf: @~[mut u32]};

fn add_input(st: sha1state, msg: ~[u8]) {
fn add_input(st: &sha1state, msg: &[u8]) {
assert (!st.computed);
for vec::each(msg) |element| {
st.msg_block[st.msg_block_idx] = element;
Expand All @@ -76,7 +79,7 @@ fn sha1() -> sha1 {
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.work_buf) == work_buf_len);
let mut t: int; // Loop counter
Expand Down Expand Up @@ -155,10 +158,10 @@ fn sha1() -> sha1 {
fn circular_shift(bits: u32, word: u32) -> u32 {
return word << bits | word >> 32u32 - bits;
}
fn mk_result(st: sha1state) -> ~[u8] {
if !st.computed { pad_msg(st); st.computed = true; }
fn mk_result(st: &sha1state) -> ~[u8] {
if !(*st).computed { pad_msg(st); (*st).computed = true; }
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 a = (hpart >> 24u32 & 0xFFu32) as u8;
let b = (hpart >> 16u32 & 0xFFu32) as u8;
Expand All @@ -178,40 +181,40 @@ fn sha1() -> sha1 {
* call process_msg_block() appropriately. When it returns, it
* can be assumed that the message digest has been computed.
*/
fn pad_msg(st: sha1state) {
assert (vec::len(st.msg_block) == msg_block_len);
fn pad_msg(st: &sha1state) {
assert (vec::len((*st).msg_block) == msg_block_len);

/*
* 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
* block, process it, and then continue padding into a second block.
*/
if st.msg_block_idx > 55u {
st.msg_block[st.msg_block_idx] = 0x80u8;
st.msg_block_idx += 1u;
while st.msg_block_idx < msg_block_len {
st.msg_block[st.msg_block_idx] = 0u8;
st.msg_block_idx += 1u;
if (*st).msg_block_idx > 55u {
(*st).msg_block[(*st).msg_block_idx] = 0x80u8;
(*st).msg_block_idx += 1u;
while (*st).msg_block_idx < msg_block_len {
(*st).msg_block[(*st).msg_block_idx] = 0u8;
(*st).msg_block_idx += 1u;
}
process_msg_block(st);
} else {
st.msg_block[st.msg_block_idx] = 0x80u8;
st.msg_block_idx += 1u;
(*st).msg_block[(*st).msg_block_idx] = 0x80u8;
(*st).msg_block_idx += 1u;
}
while st.msg_block_idx < 56u {
st.msg_block[st.msg_block_idx] = 0u8;
st.msg_block_idx += 1u;
while (*st).msg_block_idx < 56u {
(*st).msg_block[(*st).msg_block_idx] = 0u8;
(*st).msg_block_idx += 1u;
}

// Store the message length as the last 8 octets
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[58] = (st.len_high >> 8u32 & 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[61] = (st.len_low >> 16u32 & 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[56] = ((*st).len_high >> 24u32 & 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[59] = ((*st).len_high & 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[62] = ((*st).len_low >> 8u32 & 0xFFu32) as u8;
(*st).msg_block[63] = ((*st).len_low & 0xFFu32) as u8;
process_msg_block(st);
}

Expand All @@ -228,13 +231,16 @@ fn sha1() -> sha1 {
self.h[4] = 0xC3D2E1F0u32;
self.computed = false;
}
fn input(msg: ~[u8]) { add_input(self, msg); }
fn input_str(msg: ~str) { add_input(self, str::to_bytes(msg)); }
fn result() -> ~[u8] { return mk_result(self); }
fn input(msg: &[u8]) { add_input(&self, msg); }
fn input_str(msg: &str) {
let bs = str::to_bytes(msg);
add_input(&self, bs);
}
fn result() -> ~[u8] { return mk_result(&self); }
fn result_str() -> ~str {
let r = mk_result(self);
let rr = mk_result(&self);
let mut s = ~"";
for vec::each(r) |b| { s += uint::to_str(b as uint, 16u); }
for vec::each(rr) |b| { s += uint::to_str(b as uint, 16u); }
return s;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/libstd/timer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Utilities that leverage libuv's `uv_timer_*` API

#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];

import uv = uv;
import uv::iotask;
import iotask::iotask;
Expand All @@ -24,7 +27,7 @@ export delayed_send, sleep, recv_timeout;
* * val - a value of type T to send over the provided `ch`
*/
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 {
let timer_done_po = core::comm::port::<()>();
let timer_done_ch = core::comm::chan(timer_done_po);
Expand Down