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