12
12
* the `reset` method.
13
13
*/
14
14
15
+ #[ forbid( deprecated_mode) ] ;
16
+ #[ forbid( deprecated_pattern) ] ;
17
+
15
18
/*
16
19
* A SHA-1 implementation derived from Paul E. Jones's reference
17
20
* implementation, which is written for clarity, not speed. At some
@@ -22,9 +25,9 @@ export sha1;
22
25
/// The SHA-1 interface
23
26
trait sha1 {
24
27
/// Provide message input as bytes
25
- fn input ( ~ [ u8 ] ) ;
28
+ fn input ( ( & [ u8 ] ) ) ;
26
29
/// Provide message input as string
27
- fn input_str ( ~ str ) ;
30
+ fn input_str ( ( & str ) ) ;
28
31
/**
29
32
* Read the digest as a vector of 20 bytes. After calling this no further
30
33
* input may be provided until reset is called.
@@ -60,7 +63,7 @@ fn sha1() -> sha1 {
60
63
mut computed : bool ,
61
64
work_buf : @~[ mut u32] } ;
62
65
63
- fn add_input ( st : sha1state , msg : ~ [ u8 ] ) {
66
+ fn add_input ( st : & sha1state , msg : & [ u8 ] ) {
64
67
assert ( !st. computed ) ;
65
68
for vec:: each( msg) |element| {
66
69
st. msg_block [ st. msg_block_idx ] = element;
@@ -76,7 +79,7 @@ fn sha1() -> sha1 {
76
79
if st. msg_block_idx == msg_block_len { process_msg_block ( st) ; }
77
80
}
78
81
}
79
- fn process_msg_block ( st : sha1state ) {
82
+ fn process_msg_block ( st : & sha1state ) {
80
83
assert ( vec:: len ( st. h ) == digest_buf_len) ;
81
84
assert ( vec:: len ( * st. work_buf ) == work_buf_len) ;
82
85
let mut t: int ; // Loop counter
@@ -155,10 +158,10 @@ fn sha1() -> sha1 {
155
158
fn circular_shift ( bits : u32 , word : u32 ) -> u32 {
156
159
return word << bits | word >> 32u32 - bits;
157
160
}
158
- fn mk_result ( st : sha1state ) -> ~[ u8 ] {
159
- if !st . computed { pad_msg ( st) ; st . computed = true ; }
161
+ fn mk_result ( st : & sha1state ) -> ~[ u8 ] {
162
+ if !( * st ) . computed { pad_msg ( st) ; ( * st ) . computed = true ; }
160
163
let mut rs: ~[ u8 ] = ~[ ] ;
161
- for vec:: each_mut( st . h) |ptr_hpart| {
164
+ for vec:: each_mut( ( * st ) . h) |ptr_hpart| {
162
165
let hpart = * ptr_hpart;
163
166
let a = ( hpart >> 24u32 & 0xFFu32 ) as u8 ;
164
167
let b = ( hpart >> 16u32 & 0xFFu32 ) as u8 ;
@@ -178,40 +181,40 @@ fn sha1() -> sha1 {
178
181
* call process_msg_block() appropriately. When it returns, it
179
182
* can be assumed that the message digest has been computed.
180
183
*/
181
- fn pad_msg ( st : sha1state ) {
182
- assert ( vec:: len ( st . msg_block ) == msg_block_len) ;
184
+ fn pad_msg ( st : & sha1state ) {
185
+ assert ( vec:: len ( ( * st ) . msg_block ) == msg_block_len) ;
183
186
184
187
/*
185
188
* Check to see if the current message block is too small to hold
186
189
* the initial padding bits and length. If so, we will pad the
187
190
* block, process it, and then continue padding into a second block.
188
191
*/
189
- if st . msg_block_idx > 55 u {
190
- st . msg_block [ st . msg_block_idx ] = 0x80u8 ;
191
- st . msg_block_idx += 1 u;
192
- while st . msg_block_idx < msg_block_len {
193
- st . msg_block [ st . msg_block_idx ] = 0u8 ;
194
- st . msg_block_idx += 1 u;
192
+ if ( * st ) . msg_block_idx > 55 u {
193
+ ( * st ) . msg_block [ ( * st ) . msg_block_idx ] = 0x80u8 ;
194
+ ( * st ) . msg_block_idx += 1 u;
195
+ while ( * st ) . msg_block_idx < msg_block_len {
196
+ ( * st ) . msg_block [ ( * st ) . msg_block_idx ] = 0u8 ;
197
+ ( * st ) . msg_block_idx += 1 u;
195
198
}
196
199
process_msg_block ( st) ;
197
200
} else {
198
- st . msg_block [ st . msg_block_idx ] = 0x80u8 ;
199
- st . msg_block_idx += 1 u;
201
+ ( * st ) . msg_block [ ( * st ) . msg_block_idx ] = 0x80u8 ;
202
+ ( * st ) . msg_block_idx += 1 u;
200
203
}
201
- while st . msg_block_idx < 56 u {
202
- st . msg_block [ st . msg_block_idx ] = 0u8 ;
203
- st . msg_block_idx += 1 u;
204
+ while ( * st ) . msg_block_idx < 56 u {
205
+ ( * st ) . msg_block [ ( * st ) . msg_block_idx ] = 0u8 ;
206
+ ( * st ) . msg_block_idx += 1 u;
204
207
}
205
208
206
209
// Store the message length as the last 8 octets
207
- st . msg_block [ 56 ] = ( st . len_high >> 24u32 & 0xFFu32 ) as u8 ;
208
- st . msg_block [ 57 ] = ( st . len_high >> 16u32 & 0xFFu32 ) as u8 ;
209
- st . msg_block [ 58 ] = ( st . len_high >> 8u32 & 0xFFu32 ) as u8 ;
210
- st . msg_block [ 59 ] = ( st . len_high & 0xFFu32 ) as u8 ;
211
- st . msg_block [ 60 ] = ( st . len_low >> 24u32 & 0xFFu32 ) as u8 ;
212
- st . msg_block [ 61 ] = ( st . len_low >> 16u32 & 0xFFu32 ) as u8 ;
213
- st . msg_block [ 62 ] = ( st . len_low >> 8u32 & 0xFFu32 ) as u8 ;
214
- st . msg_block [ 63 ] = ( st . len_low & 0xFFu32 ) as u8 ;
210
+ ( * st ) . msg_block [ 56 ] = ( ( * st ) . len_high >> 24u32 & 0xFFu32 ) as u8 ;
211
+ ( * st ) . msg_block [ 57 ] = ( ( * st ) . len_high >> 16u32 & 0xFFu32 ) as u8 ;
212
+ ( * st ) . msg_block [ 58 ] = ( ( * st ) . len_high >> 8u32 & 0xFFu32 ) as u8 ;
213
+ ( * st ) . msg_block [ 59 ] = ( ( * st ) . len_high & 0xFFu32 ) as u8 ;
214
+ ( * st ) . msg_block [ 60 ] = ( ( * st ) . len_low >> 24u32 & 0xFFu32 ) as u8 ;
215
+ ( * st ) . msg_block [ 61 ] = ( ( * st ) . len_low >> 16u32 & 0xFFu32 ) as u8 ;
216
+ ( * st ) . msg_block [ 62 ] = ( ( * st ) . len_low >> 8u32 & 0xFFu32 ) as u8 ;
217
+ ( * st ) . msg_block [ 63 ] = ( ( * st ) . len_low & 0xFFu32 ) as u8 ;
215
218
process_msg_block ( st) ;
216
219
}
217
220
@@ -228,13 +231,16 @@ fn sha1() -> sha1 {
228
231
self . h [ 4 ] = 0xC3D2E1F0u32 ;
229
232
self . computed = false ;
230
233
}
231
- fn input ( msg : ~[ u8 ] ) { add_input ( self , msg) ; }
232
- fn input_str ( msg : ~str ) { add_input ( self , str:: to_bytes ( msg) ) ; }
233
- fn result ( ) -> ~[ u8 ] { return mk_result ( self ) ; }
234
+ fn input ( msg : & [ u8 ] ) { add_input ( & self , msg) ; }
235
+ fn input_str ( msg : & str ) {
236
+ let bs = str:: to_bytes ( msg) ;
237
+ add_input ( & self , bs) ;
238
+ }
239
+ fn result ( ) -> ~[ u8 ] { return mk_result ( & self ) ; }
234
240
fn result_str ( ) -> ~str {
235
- let r = mk_result ( self ) ;
241
+ let rr = mk_result ( & self ) ;
236
242
let mut s = ~"";
237
- for vec:: each( r ) |b| { s += uint:: to_str ( b as uint , 16 u) ; }
243
+ for vec:: each( rr ) |b| { s += uint:: to_str ( b as uint , 16 u) ; }
238
244
return s;
239
245
}
240
246
}
0 commit comments