NAME

Airlock::Code - Generate, normalize, hash and compare Airlock codes

VERSION

version 0.001

SYNOPSIS

my $code = Airlock::Code->new;

my $user_code = $code->user_code;              # 'BCDFGHJK'
print $code->display($user_code);              # 'BCDF-GHJK'
my $clean = $code->normalize('bcdf ghjk');     # 'BCDFGHJK', or nothing

my $device_code = $code->secret;               # 64 hex characters
my $stored      = $code->hash($device_code);   # SHA-256, hex

DESCRIPTION

Everything Airlock does with codes: the short code a person types, the long secret a device holds, the hash that reaches the store, and a comparison that takes the same time whether or not the strings match.

alphabet

Characters a user code is drawn from. The default has no vowels, so no words appear, and nothing that is easily confused when typed.

user_code_length

Length of a user code. Default 8.

secret_bytes

Random bytes in a secret. Default 32.

user_code

my $user_code = $code->user_code;

A new random user code without separator, drawn without modulo bias.

secret

my $device_code = $code->secret;

A new random secret as hex. Used for device codes and opaque tokens.

hash

my $stored = $code->hash($device_code);

SHA-256 of a value as hex. Secrets reach the store only in this form.

normalize

my $clean = $code->normalize($typed) or return;

Turns what a person typed into the stored form: upper case, separators and whitespace removed. Returns nothing unless the result is a well-formed code.

display

print $code->display('BCDFGHJK');   # BCDF-GHJK

A code in groups of four, joined by a dash.

equals

$code->equals( $expected, $given ) or return;

Compares two strings in constant time. Returns 1 or 0.

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/Getty/p5-airlock/issues.

IRC

Join #kubernetes on irc.perl.org or message Getty directly.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHOR

Torsten Raudssus <getty@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.