File tree 1 file changed +14
-12
lines changed
1 file changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -88,11 +88,13 @@ impl Api for MockApi {
88
88
}
89
89
90
90
let mut out = Vec :: from ( human. as_str ( ) ) ;
91
- let append = self . canonical_length - out. len ( ) ;
92
- if append > 0 {
93
- out. extend ( vec ! [ 0u8 ; append] ) ;
91
+ // pad to canonical_length wil NULL bytes
92
+ out. resize ( self . canonical_length , 0x00 ) ;
93
+ // shuffle to destroy the most obvious structure (https://github.com/CosmWasm/cosmwasm/issues/552)
94
+ for _ in 0 ..18 {
95
+ out = riffle_shuffle ( & out) ;
94
96
}
95
- Ok ( CanonicalAddr ( Binary ( out) ) )
97
+ Ok ( out. into ( ) )
96
98
}
97
99
98
100
fn human_address ( & self , canonical : & CanonicalAddr ) -> StdResult < HumanAddr > {
@@ -102,16 +104,16 @@ impl Api for MockApi {
102
104
) ) ;
103
105
}
104
106
105
- // remove trailing 0's (TODO: fix this - but fine for first tests)
106
- let trimmed : Vec < u8 > = canonical
107
- . as_slice ( )
108
- . iter ( )
109
- . cloned ( )
110
- . filter ( | & x| x != 0 )
111
- . collect ( ) ;
107
+ let mut tmp : Vec < u8 > = canonical . clone ( ) . into ( ) ;
108
+ // Shuffle two more times which restored the original value (24 elements are back to original after 20 rounds)
109
+ for _ in 0 .. 2 {
110
+ tmp = riffle_shuffle ( & tmp ) ;
111
+ }
112
+ // Remove NULL bytes (i.e. the padding )
113
+ let trimmed = tmp . into_iter ( ) . filter ( | & x| x != 0x00 ) . collect ( ) ;
112
114
// decode UTF-8 bytes into string
113
115
let human = String :: from_utf8 ( trimmed) . map_err ( StdError :: invalid_utf8) ?;
114
- Ok ( HumanAddr ( human) )
116
+ Ok ( human. into ( ) )
115
117
}
116
118
117
119
fn debug ( & self , message : & str ) {
You can’t perform that action at this time.
0 commit comments