libid-identity 0.10.0

The libid handle transform: per-platform normalization rules and the shared vector table, mirroring HandleNormalizer.sol byte for byte.
Documentation
// Generated by scripts/regen-identity-handles.py. Do not edit.
// The source of truth is solidity/contracts/identity/handles.json.

//! Platform ids and the shared handle vector table.

/// One case from the shared table.
pub struct Vector {
    /// Platform key, as written in the source table.
    pub platform: &'static str,
    /// The handle exactly as a caller supplied it.
    pub input: &'static str,
    /// The normalized handle, or an empty string when the case is refused.
    pub output: &'static str,
    /// Whether the transform accepts this case.
    pub accepted: bool,
    /// Which refusal the case expects, when it is refused.
    pub error_kind: u8,
}

/// keccak256 of this string is the platform id.
pub const PLATFORM_X_DOMAIN: &str = "x";
/// keccak256 of this string is the platform id.
pub const PLATFORM_GITHUB_DOMAIN: &str = "github";
/// keccak256 of this string is the platform id.
pub const PLATFORM_GOOGLE_DOMAIN: &str = "google";

/// Bytes a x handle may have after normalization.
pub const MAX_LENGTH_X: usize = 15;
/// Bytes a github handle may have after normalization.
pub const MAX_LENGTH_GITHUB: usize = 39;
/// Bytes a google handle may have after normalization.
pub const MAX_LENGTH_GOOGLE: usize = 62;

/// Remove one leading `@`.
pub const STRIP_LEADING_AT_X: bool = true;
/// Validate as an address instead of a bare handle.
pub const IS_EMAIL_X: bool = false;
/// Allow `_`.
pub const ALLOW_UNDERSCORE_X: bool = true;
/// Allow `-`, but not leading, trailing or doubled.
pub const ALLOW_HYPHEN_X: bool = false;
/// Remove one leading `@`.
pub const STRIP_LEADING_AT_GITHUB: bool = true;
/// Validate as an address instead of a bare handle.
pub const IS_EMAIL_GITHUB: bool = false;
/// Allow `_`.
pub const ALLOW_UNDERSCORE_GITHUB: bool = false;
/// Allow `-`, but not leading, trailing or doubled.
pub const ALLOW_HYPHEN_GITHUB: bool = true;
/// Remove one leading `@`.
pub const STRIP_LEADING_AT_GOOGLE: bool = false;
/// Validate as an address instead of a bare handle.
pub const IS_EMAIL_GOOGLE: bool = true;
/// Allow `_`.
pub const ALLOW_UNDERSCORE_GOOGLE: bool = false;
/// Allow `-`, but not leading, trailing or doubled.
pub const ALLOW_HYPHEN_GOOGLE: bool = false;

/// A notary states wall-clock time as it observes it, so the
/// observation is never ahead. Five minutes covers clock skew between
/// the notary and the chain.
pub const FUTURE_ALLOWANCE_X: u64 = 300;
/// Same as X: notary wall-clock, five minutes for skew.
pub const FUTURE_ALLOWANCE_GITHUB: u64 = 300;
/// The OIDC circuit exposes no `iat`, so the observation is the token's
/// `exp` — Google issues about an hour of life, and the claim therefore
/// reads roughly an hour ahead of the moment it describes.
pub const FUTURE_ALLOWANCE_GOOGLE: u64 = 7200;

/// Nothing is left after the transform.
pub const ERROR_EMPTY: u8 = 0;
/// More bytes than the platform allows.
pub const ERROR_TOOLONG: u8 = 1;
/// A byte the platform does not allow.
pub const ERROR_BADCHARACTER: u8 = 2;
/// Allowed bytes in an arrangement the platform does not allow.
pub const ERROR_BADSHAPE: u8 = 3;

/// Every case, shared with Solidity and TypeScript.
pub const VECTORS: [Vector; 44] = [
    Vector {
        platform: "x",
        input: " @Alice_1 ",
        output: "alice_1",
        accepted: true,
        error_kind: 0,
    },
    Vector {
        platform: "x",
        input: "alice",
        output: "alice",
        accepted: true,
        error_kind: 0,
    },
    Vector {
        platform: "x",
        input: "@a",
        output: "a",
        accepted: true,
        error_kind: 0,
    },
    Vector {
        platform: "x",
        input: "A1_b2",
        output: "a1_b2",
        accepted: true,
        error_kind: 0,
    },
    Vector {
        platform: "x",
        input: "a12345678901234",
        output: "a12345678901234",
        accepted: true,
        error_kind: 0,
    },
    Vector {
        platform: "x",
        input: "a123456789012345",
        output: "",
        accepted: false,
        error_kind: 1,
    },
    Vector {
        platform: "x",
        input: "",
        output: "",
        accepted: false,
        error_kind: 0,
    },
    Vector {
        platform: "x",
        input: "   ",
        output: "",
        accepted: false,
        error_kind: 0,
    },
    Vector {
        platform: "x",
        input: "@",
        output: "",
        accepted: false,
        error_kind: 0,
    },
    Vector {
        platform: "x",
        input: "@@alice",
        output: "",
        accepted: false,
        error_kind: 2,
    },
    Vector {
        platform: "x",
        input: "alice-1",
        output: "",
        accepted: false,
        error_kind: 2,
    },
    Vector {
        platform: "x",
        input: "ali ce",
        output: "",
        accepted: false,
        error_kind: 2,
    },
    Vector {
        platform: "x",
        input: "ali\tce",
        output: "",
        accepted: false,
        error_kind: 2,
    },
    Vector {
        platform: "x",
        input: "ali\nce",
        output: "",
        accepted: false,
        error_kind: 2,
    },
    Vector {
        platform: "x",
        input: "alic\u{e9}",
        output: "",
        accepted: false,
        error_kind: 2,
    },
    Vector {
        platform: "x",
        input: "\talice",
        output: "",
        accepted: false,
        error_kind: 2,
    },
    Vector {
        platform: "x",
        input: "alice\t",
        output: "",
        accepted: false,
        error_kind: 2,
    },
    Vector {
        platform: "x",
        input: "\nalice",
        output: "",
        accepted: false,
        error_kind: 2,
    },
    Vector {
        platform: "x",
        input: " @ alice ",
        output: "",
        accepted: false,
        error_kind: 2,
    },
    Vector {
        platform: "github",
        input: "@Octo-Cat",
        output: "octo-cat",
        accepted: true,
        error_kind: 0,
    },
    Vector {
        platform: "github",
        input: "octocat",
        output: "octocat",
        accepted: true,
        error_kind: 0,
    },
    Vector {
        platform: "github",
        input: " OctoCat ",
        output: "octocat",
        accepted: true,
        error_kind: 0,
    },
    Vector {
        platform: "github",
        input: "a",
        output: "a",
        accepted: true,
        error_kind: 0,
    },
    Vector {
        platform: "github",
        input: "o-c",
        output: "o-c",
        accepted: true,
        error_kind: 0,
    },
    Vector {
        platform: "github",
        input: "-octocat",
        output: "",
        accepted: false,
        error_kind: 3,
    },
    Vector {
        platform: "github",
        input: "octocat-",
        output: "",
        accepted: false,
        error_kind: 3,
    },
    Vector {
        platform: "github",
        input: "octo--cat",
        output: "",
        accepted: false,
        error_kind: 3,
    },
    Vector {
        platform: "github",
        input: "octo_cat",
        output: "",
        accepted: false,
        error_kind: 2,
    },
    Vector {
        platform: "github",
        input: "-",
        output: "",
        accepted: false,
        error_kind: 3,
    },
    Vector {
        platform: "github",
        input: "",
        output: "",
        accepted: false,
        error_kind: 0,
    },
    Vector {
        platform: "github",
        input: "abcdefghijabcdefghijabcdefghijabcdefghi",
        output: "abcdefghijabcdefghijabcdefghijabcdefghi",
        accepted: true,
        error_kind: 0,
    },
    Vector {
        platform: "github",
        input: "abcdefghijabcdefghijabcdefghijabcdefghij",
        output: "",
        accepted: false,
        error_kind: 1,
    },
    Vector {
        platform: "github",
        input: "\n",
        output: "",
        accepted: false,
        error_kind: 2,
    },
    Vector {
        platform: "google",
        input: "A.B+tag@Example.COM",
        output: "a.b+tag@example.com",
        accepted: true,
        error_kind: 0,
    },
    Vector {
        platform: "google",
        input: "alice@example.com",
        output: "alice@example.com",
        accepted: true,
        error_kind: 0,
    },
    Vector {
        platform: "google",
        input: " Alice@Example.com ",
        output: "alice@example.com",
        accepted: true,
        error_kind: 0,
    },
    Vector {
        platform: "google",
        input: "@Alice@example.com",
        output: "",
        accepted: false,
        error_kind: 3,
    },
    Vector {
        platform: "google",
        input: "alice",
        output: "",
        accepted: false,
        error_kind: 3,
    },
    Vector {
        platform: "google",
        input: "@example.com",
        output: "",
        accepted: false,
        error_kind: 3,
    },
    Vector {
        platform: "google",
        input: "alice@",
        output: "",
        accepted: false,
        error_kind: 3,
    },
    Vector {
        platform: "google",
        input: "",
        output: "",
        accepted: false,
        error_kind: 0,
    },
    Vector {
        platform: "google",
        input: "ali ce@example.com",
        output: "",
        accepted: false,
        error_kind: 2,
    },
    Vector {
        platform: "google",
        input: "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij@example.com",
        output: "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghij@example.com",
        accepted: true,
        error_kind: 0,
    },
    Vector {
        platform: "google",
        input: "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijk@example.com",
        output: "",
        accepted: false,
        error_kind: 1,
    },
];