| 1 | // Copyright (c) 2022, 2024 blackshirt. All rights reserved. |
| 2 | // Use of this source code is governed by a MIT License |
| 3 | // that can be found in the LICENSE file. |
| 4 | module asn1 |
| 5 | |
| 6 | struct OctetStringTest { |
| 7 | inp string |
| 8 | exp []u8 |
| 9 | err IError |
| 10 | } |
| 11 | |
| 12 | fn test_octetstring_handling() ! { |
| 13 | data := [ |
| 14 | OctetStringTest{'', [u8(0x04), 0x00], none}, |
| 15 | OctetStringTest{'abc', [u8(0x04), 0x03, 97, 98, 99], none}, |
| 16 | ] |
| 17 | |
| 18 | for o in data { |
| 19 | os := OctetString.new(o.inp)! |
| 20 | out := encode(os) or { |
| 21 | assert err == o.err |
| 22 | continue |
| 23 | } |
| 24 | assert out == o.exp |
| 25 | |
| 26 | outback, _ := OctetString.decode(out)! |
| 27 | assert outback.value == o.inp |
| 28 | } |
| 29 | } |
| 30 | |