pub fn new_with_keypair(
        ciphersuites: &[CiphersuiteName],
        backend: &impl OpenMlsCryptoProvider,
        credential_bundle: &CredentialBundle,
        mut extensions: Vec<Extension>,
        key_pair: HpkeKeyPair,
        leaf_secret: Secret,
    ) -> Result<Self, KeyPackageError> {
        if ciphersuites.is_empty() {
            let error = KeyPackageError::NoCiphersuitesSupplied;
            error!(
                "Error creating new KeyPackageBundle: No Ciphersuites specified {:?}",
                error
            );
            return Err(error);
        }

        // Detect duplicate extensions an return an error in case there is are any.
        let extensions_length = extensions.len();
        extensions.sort();
        extensions.dedup();
        if extensions_length != extensions.len() {
            let error = KeyPackageError::DuplicateExtension;
            error!(
                "Error creating new KeyPackageBundle: Duplicate Extension {:?}",
                error
            );
            return Err(error);
        }

        // First, check if one of the input extensions is a capabilities
        // extension. If there is, check if one of the extensions is a
        // capabilities extensions and if the contained ciphersuites are the
        // same as the ciphersuites passed as input. If that is not the case,
        // return an error. If none of the extensions is a capabilities
        // extension, create one that supports the given ciphersuites and that
        // is otherwise default.

        match extensions
            .iter()
            .find(|e| e.extension_type() == ExtensionType::Capabilities)
        {
            Some(extension) => {
                let capabilities_extension = extension.as_capabilities_extension().unwrap();
                if capabilities_extension.ciphersuites() != ciphersuites {
                    let error = KeyPackageError::CiphersuiteMismatch;
                    error!(
                        "Error creating new KeyPackageBundle: Invalid Capabilities Extensions {:?}",
                        error
                    );
                    return Err(error);
                }
            }

            None => extensions.push(Extension::Capabilities(CapabilitiesExtension::new(
                None,
                Some(ciphersuites),
                None,
            ))),
        };

        // Check if there is a lifetime extension. If not, add one that is at
        // least valid.
        if !extensions
            .iter()
            .any(|e| e.extension_type() == ExtensionType::Lifetime)
        {
            extensions.push(Extension::LifeTime(LifetimeExtension::default()));
        }
        let key_package = KeyPackage::new(
            ciphersuites[0],
            backend,
            key_pair.public.into(),
            credential_bundle,
            extensions,
        )?;
        Ok(KeyPackageBundle {
            key_package,
            private_key: key_pair.private.into(),
            leaf_secret,
        })
    }
/// Create a new `KeyPackageBundle` for the given `ciphersuite`, `identity`,
/// and `extensions`, using the given HPKE `key_pair`.
///
/// Note that the capabilities extension gets added automatically, based on
/// the configuration. The ciphersuite for this key package bundle is the
/// first one in the `ciphersuites` list. If a capabilities extension is
/// included in the extensions, its supported ciphersuites have to match the
/// `ciphersuites` list.
///
/// Returns an `DuplicateExtension` error if `extensions` contains multiple
/// extensions of the same type.
///
/// Returns a new `KeyPackageBundle`.


Note that the capabilities extension gets added automatically, based on
the configuration. The ciphersuite for this key package bundle is the
first one in the `ciphersuites` list. If a capabilities extension is
included in the extensions, its supported ciphersuites have to match the
`ciphersuites` list.

Returns an `DuplicateExtension` error if `extensions` contains multiple
extensions of the same type.

Returns a new `KeyPackageBundle`.
Note that the capabilities extension gets added automatically based on the configuration . The ciphersuite for this key package bundle is the first one in the ` ciphersuites ` list . If a capabilities extension is included in the extensions its supported ciphersuites have to match the ` ciphersuites ` list . Returns an ` DuplicateExtension ` error if ` extensions ` contains multiple extensions of the same type . Returns a new ` KeyPackageBundle ` .
pub fn new_with_keypair(
        ciphersuites: &[CiphersuiteName],
        backend: &impl OpenMlsCryptoProvider,
        credential_bundle: &CredentialBundle,
        mut extensions: Vec<Extension>,
        key_pair: HpkeKeyPair,
        leaf_secret: Secret,
    ) -> Result<Self, KeyPackageError> {
        if ciphersuites.is_empty() {
            let error = KeyPackageError::NoCiphersuitesSupplied;
            error!(
                "Error creating new KeyPackageBundle: No Ciphersuites specified {:?}",
                error
            );
            return Err(error);
        }
        // Detect duplicate extensions an return an error in case there is are any.
        let extensions_length = extensions.len();
        extensions.sort();
        extensions.dedup();
        if extensions_length != extensions.len() {
            let error = KeyPackageError::DuplicateExtension;
            error!(
                "Error creating new KeyPackageBundle: Duplicate Extension {:?}",
                error
            );
            return Err(error);
        }
        // First, check if one of the input extensions is a capabilities
        // extension. If there is, check if one of the extensions is a
        // capabilities extensions and if the contained ciphersuites are the
        // same as the ciphersuites passed as input. If that is not the case,
        // return an error. If none of the extensions is a capabilities
        // extension, create one that supports the given ciphersuites and that
        // is otherwise default.
        match extensions
            .iter()
            .find(|e| e.extension_type() == ExtensionType::Capabilities)
        {
            Some(extension) => {
                let capabilities_extension = extension.as_capabilities_extension().unwrap();
                if capabilities_extension.ciphersuites() != ciphersuites {
                    let error = KeyPackageError::CiphersuiteMismatch;
                    error!(
                        "Error creating new KeyPackageBundle: Invalid Capabilities Extensions {:?}",
                        error
                    );
                    return Err(error);
                }
            }
            None => extensions.push(Extension::Capabilities(CapabilitiesExtension::new(
                None,
                Some(ciphersuites),
                None,
            ))),
        };
        // Check if there is a lifetime extension. If not, add one that is at
        // least valid.
        if !extensions
            .iter()
            .any(|e| e.extension_type() == ExtensionType::Lifetime)
        {
            extensions.push(Extension::LifeTime(LifetimeExtension::default()));
        }
        let key_package = KeyPackage::new(
            ciphersuites[0],
            backend,
            key_pair.public.into(),
            credential_bundle,
            extensions,
        )?;
        Ok(KeyPackageBundle {
            key_package,
            private_key: key_pair.private.into(),
            leaf_secret,
        })
    }
pub fn new_with_keypair ( ciphersuites : & [ CiphersuiteName ] , backend : & impl OpenMlsCryptoProvider , credential_bundle : & CredentialBundle , mut extensions : Vec < Extension > , key_pair : HpkeKeyPair , leaf_secret : Secret , ) -> Result < Self , KeyPackageError > { if ciphersuites . is_empty ( ) { let error = KeyPackageError :: NoCiphersuitesSupplied ; error ! ( " " error ) ; return Err ( error ) ; } // Detect duplicate extensions an return an error in case there is are any. let extensions_length = extensions . len ( ) ; extensions . sort ( ) ; extensions . dedup ( ) ; if extensions_length != extensions . len ( ) { let error = KeyPackageError :: DuplicateExtension ; error ! ( " " error ) ; return Err ( error ) ; } // First, check if one of the input extensions is a capabilities // extension. If there is, check if one of the extensions is a // capabilities extensions and if the contained ciphersuites are the // same as the ciphersuites passed as input. If that is not the case, // return an error. If none of the extensions is a capabilities // extension, create one that supports the given ciphersuites and that // is otherwise default. match extensions . iter ( ) . find ( | e | e . extension_type ( ) == ExtensionType :: Capabilities ) { Some ( extension ) => { let capabilities_extension = extension . as_capabilities_extension ( ) . unwrap ( ) ; if capabilities_extension . ciphersuites ( ) != ciphersuites { let error = KeyPackageError :: CiphersuiteMismatch ; error ! ( " " error ) ; return Err ( error ) ; } } None => extensions . push ( Extension :: Capabilities ( CapabilitiesExtension :: new ( None , Some ( ciphersuites ) , None , ) ) ) , } ; // Check if there is a lifetime extension. If not, add one that is at // least valid. if ! extensions . iter ( ) . any ( | e | e . extension_type ( ) == ExtensionType :: Lifetime ) { extensions . push ( Extension :: LifeTime ( LifetimeExtension :: default ( ) ) ) ; } let key_package = KeyPackage :: new ( ciphersuites [ 0 ] , backend , key_pair . public . into ( ) , credential_bundle , extensions , ) ? ; Ok ( KeyPackageBundle { key_package , private_key : key_pair . private . into ( ) , leaf_secret , } ) }
Create a new `KeyPackageBundle` for the given `ciphersuite`, `identity`,
and `extensions`, using the given HPKE `key_pair`.
Create a new ` KeyPackageBundle ` for the given ` ciphersuite ` ` identity ` and ` extensions ` using the given HPKE ` key_pair ` .
ciphersuites
&[CiphersuiteName]
backend
&impl OpenMlsCryptoProvider
credential_bundle
&CredentialBundle
extensions
Vec<Extension>
key_pair
HpkeKeyPair
leaf_secret
Secret
ciphersuites
&[CiphersuiteName]
backend
&impl OpenMlsCryptoProvider
credential_bundle
&CredentialBundle
extensions
Vec<Extension>
key_pair
HpkeKeyPair
leaf_secret
Secret