| 18 | ]; |
| 19 | |
| 20 | pub fn double_padding(num_bytes: u32) -> (Vec<Script>, u32) { |
| 21 | //55 bytes fits in one block |
| 22 | //56 to 64 requires two block padding |
| 23 | |
| 24 | let mut chunks = num_bytes / 64; |
| 25 | chunks += 1; |
| 26 | |
| 27 | if num_bytes % 64 > 55 { |
| 28 | let mut bytes_left_first_padding = 64 - (num_bytes % 64); |
| 29 | bytes_left_first_padding -= 1; // remove the 0x80 that will be added always |
| 30 | let script1 = script! { |
| 31 | 8 |
| 32 | 0 |
| 33 | for _ in 0..bytes_left_first_padding { //can optimize with a couple of dups |
| 34 | 0 |
| 35 | 0 |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | let script2 = script! { |
| 40 | 0 |
| 41 | OP_DUP |
| 42 | for _ in 0..59 { |
| 43 | OP_2DUP |
| 44 | } |
| 45 | { u4_number_to_nibble( num_bytes * 8 ) } |
| 46 | }; |
| 47 | |
| 48 | chunks += 1; |
| 49 | |
| 50 | let mut results = Vec::new(); |
| 51 | for _ in 0..(chunks - 2) { |
| 52 | results.push(script! {}); |
| 53 | } |
| 54 | results.push(script1); |
| 55 | results.push(script2); |
| 56 | |
| 57 | (results, chunks) |
| 58 | } else { |
| 59 | let (script1, _) = padding(num_bytes); |
| 60 | let mut results = Vec::new(); |
| 61 | for _ in 0..(chunks - 1) { |
| 62 | results.push(script! {}); |
| 63 | } |
| 64 | results.push(script1); |
| 65 | (results, chunks) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | pub fn padding(num_bytes: u32) -> (Script, u32) { |
| 70 | let l = (num_bytes * 8) as i32; |