identity_storage/key_storage/key_id.rs
// Copyright 2020-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
/// An identifier for a private key stored in a key storage.
///
/// This type is returned by a key storage implementation when
/// generating cryptographic key pairs and later used as a parameter when signing data.
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct KeyId(String);
impl KeyId {
/// Creates a new key identifier from a string.
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}
/// Returns string representation of the key id.
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for KeyId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
impl From<KeyId> for String {
fn from(value: KeyId) -> Self {
value.0
}
}