mirror of
https://github.com/zerotier/identity.git
synced 2026-05-22 16:29:03 -07:00
corrected constants
This commit is contained in:
+2
-1
@@ -30,7 +30,8 @@ impl Address {
|
||||
|
||||
pub const SIZE: usize = 48;
|
||||
/// Length of a full address in string format.
|
||||
pub const STRING_SIZE: usize = 76;
|
||||
pub const STRING_SIZE: usize = 81;
|
||||
pub const STRING_SIZE_NO_PREFIX: usize = 76;
|
||||
|
||||
/// Get this address as a raw byte array.
|
||||
#[inline(always)]
|
||||
|
||||
+10
-13
@@ -195,7 +195,7 @@ impl<'a> ToString for PeerIdentifierRef<'a> {
|
||||
match self {
|
||||
Self::Identity(id) => id.to_string(),
|
||||
Self::Address(addr) => addr.to_string(),
|
||||
Self::Short(addr) => addr.to_string(),
|
||||
Self::Short(addr) => addr.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -204,7 +204,7 @@ impl ToString for PeerIdentifier {
|
||||
match self {
|
||||
Self::Identity(id) => id.to_string(),
|
||||
Self::Address(addr) => addr.to_string(),
|
||||
Self::Short(addr) => addr.to_string(),
|
||||
Self::Short(addr) => addr.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -212,7 +212,7 @@ impl ToString for AnyAddress {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
Self::Address(addr) => addr.to_string(),
|
||||
Self::Short(addr) => addr.to_string(),
|
||||
Self::Short(addr) => addr.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -248,7 +248,7 @@ impl<'a> serde::Serialize for PeerIdentifierRef<'a> {
|
||||
match self {
|
||||
Self::Identity(id) => id.serialize(s),
|
||||
Self::Address(addr) => addr.serialize(s),
|
||||
Self::Short(addr) => addr.serialize(s),
|
||||
Self::Short(addr) => addr.serialize(s),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -257,7 +257,7 @@ impl serde::Serialize for PeerIdentifier {
|
||||
match self {
|
||||
Self::Identity(id) => id.serialize(s),
|
||||
Self::Address(addr) => addr.serialize(s),
|
||||
Self::Short(addr) => addr.serialize(s),
|
||||
Self::Short(addr) => addr.serialize(s),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -265,7 +265,7 @@ impl serde::Serialize for AnyAddress {
|
||||
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
|
||||
match self {
|
||||
Self::Address(addr) => addr.serialize(s),
|
||||
Self::Short(addr) => addr.serialize(s),
|
||||
Self::Short(addr) => addr.serialize(s),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -288,13 +288,12 @@ impl<'de> Deserialize<'de> for PeerIdentifier {
|
||||
formatter.write_str("a zerotier identifier")
|
||||
}
|
||||
|
||||
fn visit_bytes<E: serde::de::Error>(self, v: &[u8]) -> Result<Self::Value, E>
|
||||
{
|
||||
fn visit_bytes<E: serde::de::Error>(self, v: &[u8]) -> Result<Self::Value, E> {
|
||||
match v.len() {
|
||||
Identity::SIZE => Identity::from_bytes(v).map(Self::Value::Identity),
|
||||
Address::SIZE => Address::from_bytes(v).map(Self::Value::Address),
|
||||
ShortAddress::SIZE => ShortAddress::from_bytes(v).map(Self::Value::Short),
|
||||
_ => return Err(serde::de::Error::custom(ADDRESS_ERR.0))
|
||||
_ => return Err(serde::de::Error::custom(ADDRESS_ERR.0)),
|
||||
}
|
||||
.map_err(|_| serde::de::Error::custom(ADDRESS_ERR.0))
|
||||
}
|
||||
@@ -321,12 +320,11 @@ impl<'de> Deserialize<'de> for AnyAddress {
|
||||
formatter.write_str("a zerotier identifier")
|
||||
}
|
||||
|
||||
fn visit_bytes<E: serde::de::Error>(self, v: &[u8]) -> Result<Self::Value, E>
|
||||
{
|
||||
fn visit_bytes<E: serde::de::Error>(self, v: &[u8]) -> Result<Self::Value, E> {
|
||||
match v.len() {
|
||||
Address::SIZE => Address::from_bytes(v).map(Self::Value::Address),
|
||||
ShortAddress::SIZE => ShortAddress::from_bytes(v).map(Self::Value::Short),
|
||||
_ => return Err(serde::de::Error::custom(ADDRESS_ERR.0))
|
||||
_ => return Err(serde::de::Error::custom(ADDRESS_ERR.0)),
|
||||
}
|
||||
.map_err(|_| serde::de::Error::custom(ADDRESS_ERR.0))
|
||||
}
|
||||
@@ -336,7 +334,6 @@ impl<'de> Deserialize<'de> for AnyAddress {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Start of Conversions */
|
||||
|
||||
impl<'a> From<&'a PeerIdentifier> for PeerIdentifierRef<'a> {
|
||||
|
||||
@@ -30,8 +30,12 @@ pub struct Identity {
|
||||
impl Identity {
|
||||
pub const SIZE: usize = P384_IDENTITY_SIZE;
|
||||
|
||||
pub const STRING_SIZE: usize = 547;
|
||||
pub const STRING_SIZE_NO_PREFIX: usize = 542;
|
||||
pub const STRING_SIZE: usize = 548;
|
||||
pub const STRING_SIZE_NO_PREFIX: usize = 543;
|
||||
|
||||
pub fn prefix(&self) -> &ShortAddress {
|
||||
self.address.prefix()
|
||||
}
|
||||
|
||||
pub(crate) fn locally_validate(&self) -> bool {
|
||||
let to_sign: &[&[u8]] = &[
|
||||
|
||||
@@ -122,7 +122,7 @@ impl<'de> Deserialize<'de> for IdentitySecret {
|
||||
}
|
||||
}
|
||||
}
|
||||
return Err(serde::de::Error::custom(IDENTITY_ERR.0));
|
||||
Err(serde::de::Error::custom(IDENTITY_ERR.0))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -64,7 +64,8 @@ mod tests {
|
||||
let start = ms_monotonic();
|
||||
for _ in 0..3 {
|
||||
let secret = p384::IdentitySecret::generate(1);
|
||||
println!("P: {}", secret.public.to_string());
|
||||
let s = secret.public.to_string();
|
||||
println!("P: {} ({})", s, s.len());
|
||||
}
|
||||
let end = ms_monotonic();
|
||||
println!("p384 generation time: {} ms/identity", ((end - start) as f64) / 3.0);
|
||||
|
||||
@@ -18,7 +18,8 @@ pub struct ShortAddress(pub(crate) [u64; 2]); // treated as [u8; 16]
|
||||
|
||||
impl ShortAddress {
|
||||
pub const SIZE: usize = 16;
|
||||
pub const STRING_SIZE: usize = 31;
|
||||
pub const STRING_SIZE: usize = 36;
|
||||
pub const STRING_SIZE_NO_PREFIX: usize = 31;
|
||||
|
||||
#[inline(always)]
|
||||
pub fn as_bytes(&self) -> &[u8; Self::SIZE] {
|
||||
@@ -120,7 +121,7 @@ impl FromStr for ShortAddress {
|
||||
}
|
||||
}
|
||||
}
|
||||
return Err(ADDRESS_ERR);
|
||||
Err(ADDRESS_ERR)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user