pub async fn create_basic_identity() -> Result<Box<dyn Identity + Send + Sync>, String> {
    let rng = ring::rand::SystemRandom::new();
    let key_pair = ring::signature::Ed25519KeyPair::generate_pkcs8(&rng)
        .expect("Could not generate a key pair.");

    Ok(Box::new(BasicIdentity::from_key_pair(
        Ed25519KeyPair::from_pkcs8(key_pair.as_ref()).expect("Could not read the key pair."),
    )))
}
// The SoftHSM library doesn't like to have two contexts created/initialized at once.
// Trying to create two HardwareIdentity instances at the same time results in this error:
//    Unable to create hw identity: PKCS#11: CKR_CRYPTOKI_ALREADY_INITIALIZED (0x191)
//
// To avoid this, we use a basic identity for any second identity in tests.
//
// A shared container of Ctx objects might be possible instead, but my rust-fu is inadequate.
The SoftHSM library doesn't like to have two contexts created/initialized at once.
Trying to create two HardwareIdentity instances at the same time results in this error:
Unable to create hw identity: PKCS#11: CKR_CRYPTOKI_ALREADY_INITIALIZED (0x191)

To avoid this, we use a basic identity for any second identity in tests.

A shared container of Ctx objects might be possible instead, but my rust-fu is inadequate.
The SoftHSM library doesn ' t like to have two contexts created / initialized at once . Trying to create two HardwareIdentity instances at the same time results in this error : Unable to create hw identity : PKCS#11 : CKR_CRYPTOKI_ALREADY_INITIALIZED ( 0x191 ) To avoid this we use a basic identity for any second identity in tests . A shared container of Ctx objects might be possible instead but my rust - fu is inadequate .
pub async fn create_basic_identity() -> Result<Box<dyn Identity + Send + Sync>, String> {
    let rng = ring::rand::SystemRandom::new();
    let key_pair = ring::signature::Ed25519KeyPair::generate_pkcs8(&rng)
        .expect("Could not generate a key pair.");
    Ok(Box::new(BasicIdentity::from_key_pair(
        Ed25519KeyPair::from_pkcs8(key_pair.as_ref()).expect("Could not read the key pair."),
    )))
}
pub async fn create_basic_identity ( ) -> Result < Box < dyn Identity + Send + Sync > , String > { let rng = ring :: rand :: SystemRandom :: new ( ) ; let key_pair = ring :: signature :: Ed25519KeyPair :: generate_pkcs8 ( & rng ) . expect ( " " ) ; Ok ( Box :: new ( BasicIdentity :: from_key_pair ( Ed25519KeyPair :: from_pkcs8 ( key_pair . as_ref ( ) ) . expect ( " " ) , ) ) ) }
The SoftHSM library doesn't like to have two contexts created/initialized at once.
The SoftHSM library doesn ' t like to have two contexts created / initialized at once .