v2 / vlib / x / encoding / asn1 / octetstring_test.v
29 lines · 25 sloc · 607 bytes · fdc49dc51a0d7e83abd5b383afaaab3f2793f2cf
Raw
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.
4module asn1
5
6struct OctetStringTest {
7 inp string
8 exp []u8
9 err IError
10}
11
12fn 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