Skip to main content

libid_identity/
platforms.rs

1// Generated by scripts/regen-identity-handles.py. Do not edit.
2// The sources are the pinned libID-circuits release's platforms.json and handles.json,
3// vendored into solidity/contracts/circuits/ by scripts/vendor-circuit-verifiers.sh.
4
5//! The platform table: each platform's key, node tags and buffers, and the
6//! refusals the handle and id checks share.
7
8use std::{
9    error::Error,
10    fmt,
11};
12
13/// A platform: its key, node tags and buffers.
14pub struct Platform {
15    /// keccak256 of this string is the platform id.
16    pub key: &'static str,
17    /// An id node is SHA256 of this tag, then the id.
18    pub user_id_tag: &'static str,
19    /// A handle node is SHA256 of this tag, then the normalized handle.
20    pub handle_tag: &'static str,
21    /// How long a handle may be.
22    pub rules: crate::Rules,
23    /// How long an id may be, and whether it is a number.
24    pub id_rules: crate::IdRules,
25}
26
27/// keccak256 of this string is the platform id.
28pub const PLATFORM_GOOGLE_KEY: &str = "google";
29/// keccak256 of this string is the platform id.
30pub const PLATFORM_X_KEY: &str = "x";
31/// keccak256 of this string is the platform id.
32pub const PLATFORM_GITHUB_KEY: &str = "github";
33/// keccak256 of this string is the platform id.
34pub const PLATFORM_TELEGRAM_KEY: &str = "telegram";
35
36/// The google platform.
37pub const PLATFORM_GOOGLE: Platform = Platform {
38    key: PLATFORM_GOOGLE_KEY,
39    user_id_tag: "libid.google.user-id",
40    handle_tag: "libid.google.handle",
41    rules: crate::Rules {
42        max_length: 62,
43    },
44    id_rules: crate::IdRules {
45        max_length: 31,
46        decimal: false,
47    },
48};
49/// The x platform.
50pub const PLATFORM_X: Platform = Platform {
51    key: PLATFORM_X_KEY,
52    user_id_tag: "libid.x.user-id",
53    handle_tag: "libid.x.handle",
54    rules: crate::Rules {
55        max_length: 39,
56    },
57    id_rules: crate::IdRules {
58        max_length: 20,
59        decimal: true,
60    },
61};
62/// The github platform.
63pub const PLATFORM_GITHUB: Platform = Platform {
64    key: PLATFORM_GITHUB_KEY,
65    user_id_tag: "libid.github.user-id",
66    handle_tag: "libid.github.handle",
67    rules: crate::Rules {
68        max_length: 39,
69    },
70    id_rules: crate::IdRules {
71        max_length: 20,
72        decimal: true,
73    },
74};
75/// The telegram platform.
76pub const PLATFORM_TELEGRAM: Platform = Platform {
77    key: PLATFORM_TELEGRAM_KEY,
78    user_id_tag: "libid.telegram.user-id",
79    handle_tag: "libid.telegram.handle",
80    rules: crate::Rules {
81        max_length: 32,
82    },
83    id_rules: crate::IdRules {
84        max_length: 20,
85        decimal: true,
86    },
87};
88
89/// Every platform, in table order.
90pub static PLATFORMS: [Platform; 4] = [PLATFORM_GOOGLE, PLATFORM_X, PLATFORM_GITHUB, PLATFORM_TELEGRAM];
91
92/// The platform with this key, if the table names it.
93pub fn platform(key: &str) -> Option<&'static Platform> {
94    PLATFORMS.iter().find(|p| p.key == key)
95}
96
97/// Why a handle was refused.
98#[derive(Debug, Clone, Copy, PartialEq, Eq)]
99pub enum HandleError {
100    /// Zero bytes.
101    Empty,
102    /// More bytes than the platform's buffer in platforms.json.
103    TooLong,
104    /// A byte outside printable ASCII, a quote or a backslash.
105    BadCharacter,
106}
107
108impl fmt::Display for HandleError {
109    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
110        f.write_str(match self {
111            Self::Empty => "the handle is empty",
112            Self::TooLong => "the handle is too long for this platform",
113            Self::BadCharacter => "the handle has a byte outside printable ASCII, or a quote or backslash",
114        })
115    }
116}
117
118impl Error for HandleError {}
119
120/// Why no circuit would hash an id.
121#[derive(Debug, Clone, Copy, PartialEq, Eq)]
122pub enum IdError {
123    /// Zero bytes.
124    Empty,
125    /// More bytes than the platform's buffer in platforms.json.
126    TooLong,
127    /// A byte outside printable ASCII, a quote, a backslash, or a non-digit in a decimal id.
128    BadCharacter,
129}
130
131impl fmt::Display for IdError {
132    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
133        f.write_str(match self {
134            Self::Empty => "the id is empty",
135            Self::TooLong => "the id is too long for this platform",
136            Self::BadCharacter => "the id has a byte this platform does not allow",
137        })
138    }
139}
140
141impl Error for IdError {}