| 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 IA5StringTest { |
| 7 | src string |
| 8 | out []u8 |
| 9 | err IError |
| 10 | } |
| 11 | |
| 12 | fn test_ia5string_handling() ! { |
| 13 | data := [ |
| 14 | IA5StringTest{'test', [u8(22), 4, 116, 101, 115, 116], none}, |
| 15 | IA5StringTest{'abc', '\x16\x03abc'.bytes(), none}, |
| 16 | IA5StringTest{`🚀`.str(), []u8{}, error('IA5String: contains non-ascii chars')}, |
| 17 | IA5StringTest{')', '\x16\x01)'.bytes(), none}, |
| 18 | IA5StringTest{'\x13\x03ab\x00', []u8{}, error('IA5String: contains non-ascii chars')}, |
| 19 | ] |
| 20 | |
| 21 | for c in data { |
| 22 | s := IA5String.new(c.src) or { |
| 23 | assert err == c.err |
| 24 | continue |
| 25 | } |
| 26 | out := encode(s) or { |
| 27 | assert err == c.err |
| 28 | continue |
| 29 | } |
| 30 | assert out == c.out |
| 31 | |
| 32 | // unpack back |
| 33 | mut p := Parser.new(out) |
| 34 | ret := IA5String.parse(mut p) or { |
| 35 | assert err == c.err |
| 36 | continue |
| 37 | } |
| 38 | |
| 39 | assert ret.tag().tag_number() == 22 |
| 40 | assert ret.tag().tag_class() == TagClass.universal |
| 41 | assert ret.tag().is_constructed() == false |
| 42 | } |
| 43 | } |
| 44 | |