libslug 0.9.1

A Rust Library For Cryptography Intended For Slug20 That Supports X59 Certificate Format and Post-Quantum Cryptography
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
//! # ED25519 Digital Signature
//! 
//! This contains the ED25519 Digital Signature scheme using dalek's audited crate. It implements zeroize, serialization, and other common utilties and makes it easy to sign, as well as store keys.
//! 
//! ## Features
//! 
//! ### Generation
//! 
//! - [X] Operating System Randomness
//! - [X] SecureRand
//! - [X] SecureRand with determinstic generation
//! - [X] BIP39
//! 
//! ### Signing
//! 
//! - [X] Sign
//! - [ ] Sign with Hedged Signatures
//! 
//! ### Verification
//! 
//! - [X] Verify
//! 
//! ### Encodings
//! 
//! Supports multiple encodings, including hexadecimal, base32, and base58.
//! 
//! ## TODO
//! 
//! - PKCS #7
//! - More encodings
//! - Certificate Encoding

use bip39::Language;
use ed25519_dalek::{Signer,Verifier};
use ed25519_dalek::ed25519::SignatureEncoding;
use ed25519_dalek::SignatureError;
use ed25519_dalek::SigningKey;
use ed25519_dalek::VerifyingKey;
use ed25519_dalek::Signature;
use ed25519_dalek::SecretKey;
use rand::rngs::OsRng;
use zeroize::{Zeroize,ZeroizeOnDrop};
use serde::{Serialize,Deserialize};
use crate::slugcrypt::internals::bip39::SlugMnemonic;
use crate::slugcrypt::internals::csprng::SlugCSPRNG;
use crate::errors::SlugErrors;
use subtle_encoding::hex;
use subtle_encoding::Error;

use bip39::ErrorKind;

use base32;
use base58::{FromBase58,ToBase58,FromBase58Error};
use serde_big_array::BigArray;
use slugencode::prelude::*;
use pem::Pem;

use crate::slugcrypt::traits::{IntoPemPublic,IntoPemSecret,IntoPemSignature};
use crate::slugcrypt::traits::{IntoX59PublicKey,IntoX59SecretKey,IntoX59Signature};

/// # ED25519: Public Key (Verifying Key)
/// 
/// ## Description
/// 
/// 32-byte Key in ED25519. It implements zeroize and serialization.
/// 
/// It is used to verify signatures.
#[derive(Zeroize,ZeroizeOnDrop,Serialize,Deserialize, Clone, Debug, PartialEq, PartialOrd, Hash)]
pub struct ED25519PublicKey([u8;32]);

/// # ED25519: Secret Key (Signing Key)
/// 
/// ## Description
/// 
/// 32-byte Key in ED25519. It implements zeroize and serialization.
/// 
/// It is used to sign data/messages.
/// 
/// The public key can be derived from the secret key.
/// 
/// ## Generation
/// 
/// - From Operating System Randomness (OS)
/// - SecureRand (Ephermal Password + Argon2id + ChaCha20RNG + OSCSPRNG Salt)
/// - BIP39
/// 
/// ## Signing
/// 
/// - Sign message or data
#[derive(Zeroize,ZeroizeOnDrop,Serialize,Deserialize, Clone, Debug, PartialEq, PartialOrd, Hash)]
pub struct ED25519SecretKey([u8;32]);

/// # ED25519: Signature
/// 
/// ## Description
/// 
/// 64-byte signature in ED25519. It implements zeroize and serialization.
/// 
/// It is used to verify digital signatures.
#[derive(Zeroize,ZeroizeOnDrop,Debug,Serialize,Deserialize, Clone, PartialEq, PartialOrd, Hash)]
pub struct ED25519Signature(#[serde(with = "BigArray")][u8;64]);


pub mod protocol_info {
    pub const PROTOCOL_NAME: &str = "libslug20/ed25519";
    pub const PK_SIZE: usize = 32;
    pub const SK_SIZE: usize = 32;
    pub const SIG_SIZE: usize = 64;
    pub const DERIVES_PUBLIC_KEY_FROM_SECRET: bool = true;
    pub const RANDOMNESS: [&str;4] = ["Operating-System CSPRNG","SecureRand","Deterministic With Password","BIP39"];
    pub const ENCODINGS: [&str;6] = ["Hexadecimal (Upper)","Base32 (Crockford)","Base58","PEM","Base64","Base64 URL Safe"];
}

impl ED25519SecretKey {
    /// Generates from OS-Generated Random Seed
    /// 
    /// ```rust
    /// fn main() {
    ///     use libslug::slugcrypt::internals::signature::ed25519;
    /// 
    ///     // Generate Secret Key From Operating System Randomness
    ///     let sk = ed25519::ED25519SecretKey::generate();
    /// }
    /// ```
    pub fn generate() -> ED25519SecretKey {
        let csprng = SlugCSPRNG::os_rand();
        let signing_key = SigningKey::from_bytes(&csprng);

        return ED25519SecretKey(signing_key.to_bytes())
    }
    /// Generates ED25519 Secret Key From Password With OS-Generated Salt using Argon2id and pushes into ChaCha20RNG to generate seed.
    pub fn generate_securerand(pass: &str) -> ED25519SecretKey {
        let csprng = SlugCSPRNG::new(pass);
        let signing_key = SigningKey::from_bytes(&csprng);

        return ED25519SecretKey(signing_key.to_bytes())
    }
    /// \[Determinstic] Generates Determinstically (warning: some security caution as this is deterministic with password and salt)
    pub fn generate_deterministic(pass: &str, salt: &str) -> ED25519SecretKey {
        let csprng = SlugCSPRNG::derive_from_password_with_salt(pass, salt);
        let signing_key = SigningKey::from_bytes(&csprng);

        return ED25519SecretKey(signing_key.to_bytes());
    }
    /// From BIP39 (Generation or From)
    pub fn from_bip39(mnemonic: SlugMnemonic, password: &str) -> Result<Self,ErrorKind> {
        let seed = mnemonic.to_seed(password)?;
        Ok(Self::from_bytes(&seed).unwrap())
    }
    /// to byte array of 32 bytes
    pub fn to_bytes(&self) -> [u8;32] {
        self.0
    }
    /// as bytes
    pub fn as_bytes(&self) -> &[u8] {
        &self.0
    }
    pub fn to_vec(&self) -> Vec<u8> {
        self.0.to_vec()
    }
    /// [Encoding] UPPER-HEXADECIMAL
    pub fn to_hex_string(&self) -> String {
        String::from_utf8(hex::encode_upper(self.0)).unwrap()
    }
    /// [Encoding] Decode From UPPER-HEXADECIMAL
    pub fn from_hex_string<T: AsRef<str>>(hex_str: T) -> Result<Vec<u8>,Error> {
        let bytes = hex::decode_upper(hex_str.as_ref().as_bytes())?;
        Ok(bytes)
    }
    /// from bytes
    pub fn from_bytes(bytes: &[u8]) -> Result<ED25519SecretKey, SlugErrors> {
        let mut secret_key_array: [u8;32] = [0u8;32];
        
        if bytes.len() == 32 {
            secret_key_array.copy_from_slice(bytes);
            return Ok(ED25519SecretKey(secret_key_array))
        }
        else {
            return Err(SlugErrors::InvalidLengthFromBytes)
        }
    }
    /// to usable type
    pub fn to_usable_type(&self) -> SigningKey {
        SigningKey::from_bytes(&self.0)
    }
    /// into public key
    pub fn public_key(&self) -> Result<ED25519PublicKey,SignatureError> {
        let vk = self.to_usable_type().verifying_key();
        Ok(ED25519PublicKey(vk.to_bytes()))
    }
    /// # Signing
    /// 
    /// Signs a message or data.
    pub fn sign<T: AsRef<[u8]>>(&self, msg: T) -> Result<ED25519Signature,SignatureError> {
        let signature = self.to_usable_type().try_sign(msg.as_ref())?;


        return Ok(ED25519Signature(signature.to_bytes()))
    }
    /// # To PEM
    /// 
    /// Encode to PEM format
    pub fn to_pem(&self) -> String {
        let pem = Pem::new("ED25519 Secret Key", &self.0);
        let x = pem::encode(&pem);
        return x
    }
    /// # From PEM
    /// 
    /// Decode from PEM format
    pub fn from_pem<T: AsRef<str>>(pem_str: T) -> Result<Self,SlugErrors> {
        let pem = pem::parse(pem_str.as_ref()).unwrap();
        if pem.tag() != "ED25519 Secret Key" {
            return Err(SlugErrors::Other(String::from("ED25519 From Pem Failure")))
        }
        ED25519SecretKey::from_bytes(&pem.contents())
    }
    pub fn from_slice(bytes: &[u8]) -> Result<Self,SlugErrors> {
        let mut x: [u8;32] = [0u8;32];

        if bytes.len() == 32 {
            x.copy_from_slice(bytes);
        }
        else {
            return Err(SlugErrors::InvalidLengthFromBytes)
        }
        Ok(Self::from_bytes(&x).unwrap())
    }
    pub fn to_hexadecimal(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Hex).encode(&self.0)?;
        Ok(x)
    }
    pub fn to_base32(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Base32).encode(&self.0)?;
        Ok(x)
    }
    pub fn to_base58(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Base58).encode(&self.0)?;
        Ok(x)
    }
    pub fn to_base64(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Base64).encode(&self.0)?;
        Ok(x)
    }
    pub fn to_base64_url_safe(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Base64urlsafe).encode(&self.0)?;
        Ok(x)
    }
    pub fn to_base32_unpadded(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Base32unpadded).encode(&self.0)?;
        Ok(x)
    }
    pub fn from_hex<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Hex).decode(s.as_ref())?;
        Ok(Self::from_bytes(&bytes).unwrap())
    }
    pub fn from_base32<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Base32).decode(s.as_ref())?;
        Ok(Self::from_bytes(&bytes).unwrap())
    }
    pub fn from_base58<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Base58).decode(s.as_ref())?;
        Ok(Self::from_bytes(&bytes).unwrap())
    }
    pub fn from_base64<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Base64).decode(s.as_ref())?;
        Ok(Self::from_bytes(&bytes).unwrap())
    }
    pub fn from_base64_url_safe<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Base64urlsafe).decode(s.as_ref())?;
        Ok(Self::from_bytes(&bytes).unwrap())
    }
    pub fn from_base32_unpadded<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Base32unpadded).decode(s.as_ref())?;
        Ok(Self::from_bytes(&bytes).unwrap())
    }
    pub fn public_key_bytes(&self) -> Result<[u8;32],SignatureError> {
        let vk = self.to_usable_type().verifying_key();
        Ok(vk.to_bytes())
    }
}

impl ED25519PublicKey {
    /// as bytes
    pub fn as_bytes(&self) -> &[u8] {
        &self.0
    }
    /// to byte array (32 bytes)
    pub fn to_bytes(&self) -> [u8;32] {
        self.0
    }
    /// from bytes (byte array of 32 bytes)
    pub fn from_bytes(bytes: [u8;32]) -> Self {
        Self(bytes)
    }
    pub fn from_slice(bytes: &[u8]) -> Result<Self,SlugErrors> {
        let mut x: [u8;32] = [0u8;32];

        if bytes.len() == 32 {
            x.copy_from_slice(bytes);
        }
        else {
            return Err(SlugErrors::InvalidLengthFromBytes)
        }
        Ok(Self::from_bytes(x))
    }
    /// to usable type
    fn to_usable_type(&self) -> Result<VerifyingKey,SignatureError> {
        VerifyingKey::from_bytes(&self.0)
    }
    /// # Verify (ED25519)
    /// 
    /// Verify a signature and message
    pub fn verify<T: AsRef<[u8]>>(&self, signature: ED25519Signature, msg: T) -> Result<bool,SignatureError> {
        let x = self.to_usable_type().unwrap().verify_strict(msg.as_ref(), &signature.to_usable_type())?;
        return Ok(true)
    }
    /// \[Encoding] Encode From UPPER-HEXADECIMAL
    pub fn to_hex_string(&self) -> String {
        String::from_utf8(hex::encode_upper(self.0)).unwrap()
    }
    /// \[Encoding] Decode From UPPER-HEXADECIMAL
    pub fn from_hex_string<T: AsRef<str>>(hex_str: T) -> Result<Vec<u8>,Error> {
        let bytes = hex::decode_upper(hex_str.as_ref().as_bytes())?;
        Ok(bytes)
    }
    /// \[Encoding] To Base32 string
    pub fn to_base32_string(&self) -> String {
        base32::encode(base32::Alphabet::Crockford, &self.0)
    }
    /// \[Encoding] From Base32 String
    pub fn from_base32_string<T: AsRef<str>>(bs32_str: T) -> Vec<u8> {
        let bytes = base32::decode(base32::Alphabet::Crockford, bs32_str.as_ref()).unwrap();
        return bytes
    }
    /// # To PEM
    pub fn to_pem(&self) -> String {
        let pem = Pem::new("ED25519 Public Key", &self.0);
        let x = pem::encode(&pem);
        return x
    }
    /// # From PEM
    pub fn from_pem<T: AsRef<str>>(pem_str: T) -> Result<Self,SlugErrors> {
        let pem = pem::parse(pem_str.as_ref()).unwrap();
        if pem.tag() != "ED25519 Public Key" {
            return Err(SlugErrors::Other(String::from("ED25519 From Pem Failure")))
        }
        return Ok(ED25519PublicKey::from_slice(&pem.contents()).unwrap())
    }
    pub fn to_hexadecimal(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Hex).encode(&self.0)?;
        Ok(x)
    }
    pub fn to_base32(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Base32).encode(&self.0)?;
        Ok(x)
    }
    pub fn to_base58(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Base58).encode(&self.0)?;
        Ok(x)
    }
    pub fn to_base64(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Base64).encode(&self.0)?;
        Ok(x)
    }
    pub fn to_base64_url_safe(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Base64urlsafe).encode(&self.0)?;
        Ok(x)
    }
    pub fn to_base32_unpadded(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Base32unpadded).encode(&self.0)?;
        Ok(x)
    }
    pub fn from_hex<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Hex).decode(s.as_ref())?;
        Ok(Self::from_slice(&bytes).unwrap())
    }
    pub fn from_base32<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Base32).decode(s.as_ref())?;
        Ok(Self::from_slice(&bytes).unwrap())
    }
    pub fn from_base58<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Base58).decode(s.as_ref())?;
        Ok(Self::from_slice(&bytes).unwrap())
    }
    pub fn from_base64<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Base64).decode(s.as_ref())?;
        Ok(Self::from_slice(&bytes).unwrap())
    }
    pub fn from_base64_url_safe<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Base64urlsafe).decode(s.as_ref())?;
        Ok(Self::from_slice(&bytes).unwrap())
    }
    pub fn from_base32_unpadded<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Base32unpadded).decode(s.as_ref())?;
        Ok(Self::from_slice(&bytes).unwrap())
    }
}

impl ED25519Signature {
    /// as bytes
    pub fn as_bytes(&self) -> &[u8] {
        &self.0
    }
    /// to 64-byte array
    pub fn to_bytes(&self) -> [u8;64] {
        self.0
    }
    /// from byte slice (must be 64 bytes)
    pub fn from_bytes(bytes: &[u8]) -> Result<Self,SlugErrors> {
        let mut signature_array: [u8;64] = [0u8;64];
        
        if bytes.len() == 64 {
            signature_array.copy_from_slice(bytes);
            return Ok(Self(signature_array))
        }
        else {
            return Err(SlugErrors::InvalidLengthFromBytes)
        }
    }
    /// to usable type
    pub fn to_usable_type(&self) -> Signature {
        Signature::from_bytes(&self.0)
    }
    /// to base58 string
    pub fn to_base58_string(&self) -> String {
        self.0.to_base58()
    }
    /// from base58 string (must convert into bytes)
    pub fn from_base58_string<T: AsRef<str>>(base58_str: T) -> Result<Vec<u8>,FromBase58Error> {
        let bytes = base58_str.as_ref().from_base58()?;
        Ok(bytes)
    }
    /// [Encoding] Encode From UPPER-HEXADECIMAL
    pub fn to_hex_string(&self) -> String {
        String::from_utf8(hex::encode_upper(self.0)).unwrap()
    }
    /// [Encoding] Decode From UPPER-HEXADECIMAL (must convert from bytes)
    pub fn from_hex_string<T: AsRef<str>>(hex_str: T) -> Result<Vec<u8>,Error> {
        let bytes = hex::decode_upper(hex_str.as_ref().as_bytes())?;
        Ok(bytes)
    }
    pub fn from_pem<T: AsRef<str>>(pem_str: T) -> Result<Self,SlugErrors> {
        let pem = pem::parse(pem_str.as_ref()).unwrap();
        if pem.tag() != "ED25519 Signature" {
            return Err(SlugErrors::Other(String::from("ED25519 From Pem Failure")))
        }
        ED25519Signature::from_bytes(&pem.contents())
    }
    pub fn to_pem(&self) -> String {
        let pem = Pem::new("ED25519 Signature", &self.0);
        let x = pem::encode(&pem);
        return x
    }
    pub fn to_hexadecimal(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Hex).encode(&self.0)?;
        Ok(x)
    }
    pub fn to_base32(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Base32).encode(&self.0)?;
        Ok(x)
    }
    pub fn to_base58(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Base58).encode(&self.0)?;
        Ok(x)
    }
    pub fn to_base64(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Base64).encode(&self.0)?;
        Ok(x)
    }
    pub fn to_base64_url_safe(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Base64urlsafe).encode(&self.0)?;
        Ok(x)
    }
    pub fn to_base32_unpadded(&self) -> Result<String,SlugEncodingError> {
        let x = SlugEncodingUsage::new(SlugEncodings::Base32unpadded).encode(&self.0)?;
        Ok(x)
    }
       pub fn from_hex<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Hex).decode(s.as_ref())?;
        Ok(Self::from_bytes(&bytes).unwrap())
    }
    pub fn from_base32<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Base32).decode(s.as_ref())?;
        Ok(Self::from_bytes(&bytes).unwrap())
    }
    pub fn from_base58<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Base58).decode(s.as_ref())?;
        Ok(Self::from_bytes(&bytes).unwrap())
    }
    pub fn from_base64<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Base64).decode(s.as_ref())?;
        Ok(Self::from_bytes(&bytes).unwrap())
    }
    pub fn from_base64_url_safe<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Base64urlsafe).decode(s.as_ref())?;
        Ok(Self::from_bytes(&bytes).unwrap())
    }
    pub fn from_base32_unpadded<T: AsRef<str>>(s: T) -> Result<Self,SlugEncodingError> {
        let bytes = SlugEncodingUsage::new(SlugEncodings::Base32unpadded).decode(s.as_ref())?;
        Ok(Self::from_bytes(&bytes).unwrap())
    }
}


#[test]
fn run() {
    let sk = ED25519SecretKey::generate();
    println!("Secret Key: {:?}", sk);
}

#[test]
fn ed25519() {
    let sk = ED25519SecretKey::generate();
    let cert = sk.public_key().unwrap();
}