dymokomi/luce-tls
Source of release 0.7.1
0.7.1 / tests / tls / main.lucb
import tls
func nibble(c: u8) -> u8:
if c >= '0' and c <= '9': return c - '0'
return c - 'a' + 10
pub func main(arguments: str[]) -> i32!:
_ = arguments
var header: u8[5]
header[0] = 22
header[1] = 3
header[2] = 3
header[3] = 0
header[4] = 10
let parsed = try tls.parse_record(header)
assert(parsed.content_type == 22 and parsed.version == 0x0303 and parsed.length == 10)
assert(tls.hostname_matches("example.com", "EXAMPLE.COM"))
assert(tls.hostname_matches("*.example.com", "www.example.com"))
assert(not tls.hostname_matches("*.example.com", "a.b.example.com"))
assert(not tls.hostname_matches("example.com", "evil.com"))
var secret: u8[32]
for i in 0..<(usize)32: secret[i] = (u8)i
var out: u8[16]
try tls.expand_label(secret, b"key", b"", out)
var expect: u8[16]
let digits = b"9c9783cf77ea32d44f369da41f19f3cc"
for i in 0..<(usize)16:
expect[i] = (nibble(digits[i * 2]) << 4) | nibble(digits[i * 2 + 1])
for i in 0..<(usize)16: assert(out[i] == expect[i], "Expand-Label mismatch")
print("PASS TLS record, hostname match and Expand-Label")
return 0