Module fcp_cryptoauth::authentication [] [src]

Contains code related to the authorization challenge, as defined by https://github.com/fc00/spec/blob/10b349ab11/cryptoauth.md#authorization-challenges and https://github.com/cjdelisle/cjdns/blob/cjdns-v17.4/doc/Whitepaper.md#authentication-field

Examples

None credentials:

use fcp_cryptoauth::authentication::*;
let credentials = Credentials::None;
let bytes = credentials.to_auth_challenge_bytes(&session);
assert_eq!(bytes[0], 0u8);
// Other bytes are random, as specified.

Password credentials:

use fcp_cryptoauth::authentication::*;

let password = "foo".to_owned().into_bytes();
let credentials = Credentials::Password { password: password };
let bytes = credentials.to_auth_challenge_bytes(&session);
assert_eq!(bytes[0], 1u8);
assert_eq!(bytes[1..8], [0xad, 0xe8, 0x8f, 0xc7, 0xa2, 0x14, 0x98]); // sha256(sha256("foo"))[1..8]
assert_eq!(bytes[8..12], [0, 0, 0, 0]);

Login+Password credentials:

use fcp_cryptoauth::authentication::*;

let login = "foo".to_owned().into_bytes();
let password = "bar".to_owned().into_bytes();
let credentials = Credentials::LoginPassword { login: login, password: password };
let bytes = credentials.to_auth_challenge_bytes(&session);
assert_eq!(bytes[0], 2u8);
assert_eq!(bytes[1..8], [0x26, 0xb4, 0x6b, 0x68, 0xff, 0xc6, 0x8f]); // sha256("bar")[1..8]
assert_eq!(bytes[8..12], [0, 0, 0, 0]);

Enums

Credentials

Used for specifying authorization credentials of a peer, either oneself or an incoming peer.

Traits

ToAuthChallenge