libid-identity 0.24.0

The off-chain half of libid identity keys: per-platform handle normalization and id rules, the shared vector tables, and (feature `node`) the SHA-256 nodes a binding is stored under, matching the circuits byte for byte.
Documentation
// Generated by scripts/regen-identity-handles.py. Do not edit.
// The sources are the pinned libID-circuits release's platforms.json and handles.json,
// vendored into solidity/contracts/circuits/ by scripts/vendor-circuit-verifiers.sh.

//! The platform table: each platform's key, node tags and buffers, and the
//! refusals the handle and id checks share.

use std::{
    error::Error,
    fmt,
};

/// A platform: its key, node tags and buffers.
pub struct Platform {
    /// keccak256 of this string is the platform id.
    pub key: &'static str,
    /// An id node is SHA256 of this tag, then the id.
    pub user_id_tag: &'static str,
    /// A handle node is SHA256 of this tag, then the normalized handle.
    pub handle_tag: &'static str,
    /// How long a handle may be.
    pub rules: crate::Rules,
    /// How long an id may be, and whether it is a number.
    pub id_rules: crate::IdRules,
}

/// keccak256 of this string is the platform id.
pub const PLATFORM_GOOGLE_KEY: &str = "google";
/// keccak256 of this string is the platform id.
pub const PLATFORM_X_KEY: &str = "x";
/// keccak256 of this string is the platform id.
pub const PLATFORM_GITHUB_KEY: &str = "github";
/// keccak256 of this string is the platform id.
pub const PLATFORM_TELEGRAM_KEY: &str = "telegram";

/// The google platform.
pub const PLATFORM_GOOGLE: Platform = Platform {
    key: PLATFORM_GOOGLE_KEY,
    user_id_tag: "libid.google.user-id",
    handle_tag: "libid.google.handle",
    rules: crate::Rules {
        max_length: 62,
    },
    id_rules: crate::IdRules {
        max_length: 31,
        decimal: false,
    },
};
/// The x platform.
pub const PLATFORM_X: Platform = Platform {
    key: PLATFORM_X_KEY,
    user_id_tag: "libid.x.user-id",
    handle_tag: "libid.x.handle",
    rules: crate::Rules {
        max_length: 39,
    },
    id_rules: crate::IdRules {
        max_length: 20,
        decimal: true,
    },
};
/// The github platform.
pub const PLATFORM_GITHUB: Platform = Platform {
    key: PLATFORM_GITHUB_KEY,
    user_id_tag: "libid.github.user-id",
    handle_tag: "libid.github.handle",
    rules: crate::Rules {
        max_length: 39,
    },
    id_rules: crate::IdRules {
        max_length: 20,
        decimal: true,
    },
};
/// The telegram platform.
pub const PLATFORM_TELEGRAM: Platform = Platform {
    key: PLATFORM_TELEGRAM_KEY,
    user_id_tag: "libid.telegram.user-id",
    handle_tag: "libid.telegram.handle",
    rules: crate::Rules {
        max_length: 32,
    },
    id_rules: crate::IdRules {
        max_length: 20,
        decimal: true,
    },
};

/// Every platform, in table order.
pub static PLATFORMS: [Platform; 4] = [PLATFORM_GOOGLE, PLATFORM_X, PLATFORM_GITHUB, PLATFORM_TELEGRAM];

/// The platform with this key, if the table names it.
pub fn platform(key: &str) -> Option<&'static Platform> {
    PLATFORMS.iter().find(|p| p.key == key)
}

/// Why a handle was refused.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HandleError {
    /// Zero bytes.
    Empty,
    /// More bytes than the platform's buffer in platforms.json.
    TooLong,
    /// A byte outside printable ASCII, a quote or a backslash.
    BadCharacter,
}

impl fmt::Display for HandleError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(match self {
            Self::Empty => "the handle is empty",
            Self::TooLong => "the handle is too long for this platform",
            Self::BadCharacter => "the handle has a byte outside printable ASCII, or a quote or backslash",
        })
    }
}

impl Error for HandleError {}

/// Why no circuit would hash an id.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IdError {
    /// Zero bytes.
    Empty,
    /// More bytes than the platform's buffer in platforms.json.
    TooLong,
    /// A byte outside printable ASCII, a quote, a backslash, or a non-digit in a decimal id.
    BadCharacter,
}

impl fmt::Display for IdError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str(match self {
            Self::Empty => "the id is empty",
            Self::TooLong => "the id is too long for this platform",
            Self::BadCharacter => "the id has a byte this platform does not allow",
        })
    }
}

impl Error for IdError {}