fn try_from(attributes: Attributes) -> Result<Self> {
        // For some operations like import 0 size is permitted
        if attributes.bits == 0 {
            return Ok(attributes.bits);
        }
        match attributes.key_type {
            Type::EccKeyPair { curve_family } | Type::EccPublicKey { curve_family } => {
                match curve_family {
                    // SEC random curves over prime fields.
                    EccFamily::SecpR1 => match attributes.bits {
                        192 | 224 | 256 | 284 | 521 => Ok(attributes.bits),
                        _ => {
                            error!("Requested key size is not supported ({})", attributes.bits);
                            Err(Error::InvalidArgument)
                        }
                    },
                    // SEC Koblitz curves over prime fields.
                    EccFamily::SecpK1 => match attributes.bits {
                        192 | 224 | 256 => Ok(attributes.bits),
                        _ => {
                            error!("Requested key size is not supported ({})", attributes.bits);
                            Err(Error::InvalidArgument)
                        }
                    },
                    // SEC Koblitz curves over binary fields
                    EccFamily::SectK1 => match attributes.bits {
                        233 | 239 | 283 | 409 | 571 => Ok(attributes.bits),
                        _ => {
                            error!("Requested key size is not supported ({})", attributes.bits);
                            Err(Error::InvalidArgument)
                        }
                    },
                    // SEC random curves over binary fields
                    EccFamily::SectR1 => match attributes.bits {
                        233 | 283 | 409 | 571 => Ok(attributes.bits),
                        _ => {
                            error!("Requested key size is not supported ({})", attributes.bits);
                            Err(Error::InvalidArgument)
                        }
                    },
                    // Brainpool P random curves
                    EccFamily::BrainpoolPR1 => match attributes.bits {
                        192 | 224 | 256 | 320 | 384 | 512 => Ok(attributes.bits),
                        _ => {
                            error!("Requested key size is not supported ({})", attributes.bits);
                            Err(Error::InvalidArgument)
                        }
                    },
                    // Curve used primarily in France and elsewhere in Europe.
                    EccFamily::Frp => match attributes.bits {
                        256 => Ok(attributes.bits),
                        _ => {
                            error!("Requested key size is not supported ({})", attributes.bits);
                            Err(Error::InvalidArgument)
                        }
                    },
                    // Montgomery curves
                    EccFamily::Montgomery => match attributes.bits {
                        255 | 448 => Ok(attributes.bits),
                        _ => {
                            error!("Requested key size is not supported ({})", attributes.bits);
                            Err(Error::InvalidArgument)
                        }
                    },
                    _ => {
                        // We don't (yet?) implement checks for other curve families
                        Ok(attributes.bits)
                    }
                }
            }
            _ => {
                // TO-DO We don't (yet?) implement checks for other types
                Ok(attributes.bits)
            }
        }
    }
// Check if key size is correct for the key type
Check if key size is correct for the key type
Check if key size is correct for the key type
fn try_from(attributes: Attributes) -> Result<Self> {
        // For some operations like import 0 size is permitted
        if attributes.bits == 0 {
            return Ok(attributes.bits);
        }
        match attributes.key_type {
            Type::EccKeyPair { curve_family } | Type::EccPublicKey { curve_family } => {
                match curve_family {
                    // SEC random curves over prime fields.
                    EccFamily::SecpR1 => match attributes.bits {
                        192 | 224 | 256 | 284 | 521 => Ok(attributes.bits),
                        _ => {
                            error!("Requested key size is not supported ({})", attributes.bits);
                            Err(Error::InvalidArgument)
                        }
                    },
                    // SEC Koblitz curves over prime fields.
                    EccFamily::SecpK1 => match attributes.bits {
                        192 | 224 | 256 => Ok(attributes.bits),
                        _ => {
                            error!("Requested key size is not supported ({})", attributes.bits);
                            Err(Error::InvalidArgument)
                        }
                    },
                    // SEC Koblitz curves over binary fields
                    EccFamily::SectK1 => match attributes.bits {
                        233 | 239 | 283 | 409 | 571 => Ok(attributes.bits),
                        _ => {
                            error!("Requested key size is not supported ({})", attributes.bits);
                            Err(Error::InvalidArgument)
                        }
                    },
                    // SEC random curves over binary fields
                    EccFamily::SectR1 => match attributes.bits {
                        233 | 283 | 409 | 571 => Ok(attributes.bits),
                        _ => {
                            error!("Requested key size is not supported ({})", attributes.bits);
                            Err(Error::InvalidArgument)
                        }
                    },
                    // Brainpool P random curves
                    EccFamily::BrainpoolPR1 => match attributes.bits {
                        192 | 224 | 256 | 320 | 384 | 512 => Ok(attributes.bits),
                        _ => {
                            error!("Requested key size is not supported ({})", attributes.bits);
                            Err(Error::InvalidArgument)
                        }
                    },
                    // Curve used primarily in France and elsewhere in Europe.
                    EccFamily::Frp => match attributes.bits {
                        256 => Ok(attributes.bits),
                        _ => {
                            error!("Requested key size is not supported ({})", attributes.bits);
                            Err(Error::InvalidArgument)
                        }
                    },
                    // Montgomery curves
                    EccFamily::Montgomery => match attributes.bits {
                        255 | 448 => Ok(attributes.bits),
                        _ => {
                            error!("Requested key size is not supported ({})", attributes.bits);
                            Err(Error::InvalidArgument)
                        }
                    },
                    _ => {
                        // We don't (yet?) implement checks for other curve families
                        Ok(attributes.bits)
                    }
                }
            }
            _ => {
                // TO-DO We don't (yet?) implement checks for other types
                Ok(attributes.bits)
            }
        }
    }
fn try_from ( attributes : Attributes ) -> Result < Self > { // For some operations like import 0 size is permitted if attributes . bits == 0 { return Ok ( attributes . bits ) ; } match attributes . key_type { Type :: EccKeyPair { curve_family } | Type :: EccPublicKey { curve_family } => { match curve_family { // SEC random curves over prime fields. EccFamily :: SecpR1 => match attributes . bits { 192 | 224 | 256 | 284 | 521 => Ok ( attributes . bits ) , _ => { error ! ( " " attributes bits ) ; Err ( Error :: InvalidArgument ) } } , // SEC Koblitz curves over prime fields. EccFamily :: SecpK1 => match attributes . bits { 192 | 224 | 256 => Ok ( attributes . bits ) , _ => { error ! ( " " attributes bits ) ; Err ( Error :: InvalidArgument ) } } , // SEC Koblitz curves over binary fields EccFamily :: SectK1 => match attributes . bits { 233 | 239 | 283 | 409 | 571 => Ok ( attributes . bits ) , _ => { error ! ( " " attributes bits ) ; Err ( Error :: InvalidArgument ) } } , // SEC random curves over binary fields EccFamily :: SectR1 => match attributes . bits { 233 | 283 | 409 | 571 => Ok ( attributes . bits ) , _ => { error ! ( " " attributes bits ) ; Err ( Error :: InvalidArgument ) } } , // Brainpool P random curves EccFamily :: BrainpoolPR1 => match attributes . bits { 192 | 224 | 256 | 320 | 384 | 512 => Ok ( attributes . bits ) , _ => { error ! ( " " attributes bits ) ; Err ( Error :: InvalidArgument ) } } , // Curve used primarily in France and elsewhere in Europe. EccFamily :: Frp => match attributes . bits { 256 => Ok ( attributes . bits ) , _ => { error ! ( " " attributes bits ) ; Err ( Error :: InvalidArgument ) } } , // Montgomery curves EccFamily :: Montgomery => match attributes . bits { 255 | 448 => Ok ( attributes . bits ) , _ => { error ! ( " " attributes bits ) ; Err ( Error :: InvalidArgument ) } } , _ => { // We don't (yet?) implement checks for other curve families Ok ( attributes . bits ) } } } _ => { // TO-DO We don't (yet?) implement checks for other types Ok ( attributes . bits ) } } }
Check if key size is correct for the key type
Check if key size is correct for the key type
attributes
Attributes