Crypt-OpenToken

 view release on metacpan or  search on metacpan

lib/Crypt/OpenToken.pm  view on Meta::CPAN

    my ($self, $token_str) = @_;

    # fixup: convert trailing "*"s into "="s (OTK specific encoding)
    $token_str =~ s/(\*+)$/'=' x length($1)/e;

    # fixup: convert "_" to "/" (PingId PHP bindings encode this way)
    # fixup: convert "-" to "+" (PingId PHP bindings encode this way)
    $token_str =~ tr{_-}{/+};

    # Base64 decode it, and we're done.
    my $decoded = decode_base64($token_str);
    return $decoded;
}

# Custom Base64 encoding; OTK has some oddities in how they encode things
# using Base64.
sub _base64_encode {
    my ($self, $token_str) = @_;

    # Base64 encode the token string
    my $encoded = encode_base64($token_str, '');

t/opentoken.t  view on Meta::CPAN

    is $factory, object { prop blessed => 'Crypt::OpenToken'; }, 'instantiated token factory';
}

###############################################################################
# TEST: base64 en/decoding
base64_encoding: {
    # encoded test data taken from OTK IETF Draft
    my $encoded = "UFRLAQK9THj0okLTUB663QrJFg5qA58IDhAb93ondvcx7sY6s44eszNqAAAga5W8Dc4XZwtsZ4qV3_lDI-Zn2_yadHHIhkGqNV5J9kw*";

    my $factory   = Crypt::OpenToken->new(password => 'dummy password');
    my $decoded   = $factory->_base64_decode($encoded);
    my $roundtrip = $factory->_base64_encode($decoded);
    is $roundtrip, $encoded, 'Base64 decode/encode round-trip';
}

###############################################################################
done_testing();



( run in 0.810 second using v1.01-cache-2.11-cpan-26ccb49234f )