identity_storage/key_storage/
key_id.rs

1// Copyright 2020-2023 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4/// An identifier for a private key stored in a key storage.
5///
6/// This type is returned by a key storage implementation when
7/// generating cryptographic key pairs and later used as a parameter when signing data.
8#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
9pub struct KeyId(String);
10
11impl KeyId {
12  /// Creates a new key identifier from a string.
13  pub fn new(id: impl Into<String>) -> Self {
14    Self(id.into())
15  }
16
17  /// Returns string representation of the key id.
18  pub fn as_str(&self) -> &str {
19    &self.0
20  }
21}
22
23impl std::fmt::Display for KeyId {
24  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25    f.write_str(&self.0)
26  }
27}
28
29impl From<KeyId> for String {
30  fn from(value: KeyId) -> Self {
31    value.0
32  }
33}