Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
Utils.hexToBytes() :
- fix size 32 byte when convert hex to bytes
nirvana369 committed May 12, 2023
1 parent 545e184 commit a80e8f8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/utils.mo
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ module Utils {
let p = Iter.toArray(Iter.map(Text.toIter(hex),
func (x: Char) : Nat { Nat32.toNat(Char.toNat32(x)) }));
var res : [var Nat8] = [var];
for (i in Iter.range(0, 31)) {
for (i in Iter.range(0, p.size() / 2 - 1)) {
let a = Option.unwrap<Nat8>(map.get(p[i*2]));
let b = Option.unwrap<Nat8>(map.get(p[i*2 + 1]));
let c = 16*a + b;
@@ -339,7 +339,15 @@ module Utils {
case (#string(h)) hexToBytes(h);
};
if (expectedLength != null and ?Array.size(bytes) != expectedLength) {
Debug.trap("Expected ${expectedLength} bytes");
let errHext = switch hex {
case (#array(h)) bytesToHex(h);
case (#string(h)) h;
};
let len = switch (expectedLength) {
case null 0;
case (?l) l;
};
Debug.trap(errHext # " - Expected " # Nat.toText(len) # " bytes");
};
return bytes;
};

0 comments on commit a80e8f8

Please sign in to comment.