pub fn mask(&self, sample: &[u8]) -> Res<Vec<u8>> {
        let mut output = vec![0_u8; self.block_size()];

        match self {
            Self::Aes(context) => {
                let mut output_len: c_int = 0;
                secstatus_to_res(unsafe {
                    PK11_CipherOp(
                        **context.borrow_mut(),
                        output.as_mut_ptr(),
                        &mut output_len,
                        c_int::try_from(output.len())?,
                        (&sample[..Self::SAMPLE_SIZE]).as_ptr().cast(),
                        c_int::try_from(Self::SAMPLE_SIZE).unwrap(),
                    )
                })?;
                assert_eq!(usize::try_from(output_len).unwrap(), output.len());
                Ok(output)
            }

            Self::Chacha(key) => {
                let params: CK_CHACHA20_PARAMS = CK_CHACHA20_PARAMS {
                    pBlockCounter: sample.as_ptr() as *mut u8,
                    blockCounterBits: 32,
                    pNonce: (&sample[4..Self::SAMPLE_SIZE]).as_ptr() as *mut _,
                    ulNonceBits: 96,
                };
                let mut output_len: c_uint = 0;
                secstatus_to_res(unsafe {
                    PK11_Encrypt(
                        **key,
                        CK_MECHANISM_TYPE::from(CKM_CHACHA20),
                        &Item::wrap_struct(&params) as *const _ as *mut _,
                        (&mut output[..]).as_mut_ptr(),
                        &mut output_len,
                        c_uint::try_from(output.len())?,
                        (&output[..]).as_ptr(),
                        c_uint::try_from(output.len())?,
                    )
                })?;
                assert_eq!(usize::try_from(output_len).unwrap(), output.len());
                Ok(output)
            }
        }
    }
/// Generate a header protection mask for QUIC.
///
/// # Errors
/// An error is returned if the NSS functions fail; a sample of the
/// wrong size is the obvious cause.
/// # Panics
/// When the mechanism for our key is not supported.
Generate a header protection mask for QUIC.
Generate a header protection mask for QUIC .
pub fn mask(&self, sample: &[u8]) -> Res<Vec<u8>> {
        let mut output = vec![0_u8; self.block_size()];
        match self {
            Self::Aes(context) => {
                let mut output_len: c_int = 0;
                secstatus_to_res(unsafe {
                    PK11_CipherOp(
                        **context.borrow_mut(),
                        output.as_mut_ptr(),
                        &mut output_len,
                        c_int::try_from(output.len())?,
                        (&sample[..Self::SAMPLE_SIZE]).as_ptr().cast(),
                        c_int::try_from(Self::SAMPLE_SIZE).unwrap(),
                    )
                })?;
                assert_eq!(usize::try_from(output_len).unwrap(), output.len());
                Ok(output)
            }
            Self::Chacha(key) => {
                let params: CK_CHACHA20_PARAMS = CK_CHACHA20_PARAMS {
                    pBlockCounter: sample.as_ptr() as *mut u8,
                    blockCounterBits: 32,
                    pNonce: (&sample[4..Self::SAMPLE_SIZE]).as_ptr() as *mut _,
                    ulNonceBits: 96,
                };
                let mut output_len: c_uint = 0;
                secstatus_to_res(unsafe {
                    PK11_Encrypt(
                        **key,
                        CK_MECHANISM_TYPE::from(CKM_CHACHA20),
                        &Item::wrap_struct(&params) as *const _ as *mut _,
                        (&mut output[..]).as_mut_ptr(),
                        &mut output_len,
                        c_uint::try_from(output.len())?,
                        (&output[..]).as_ptr(),
                        c_uint::try_from(output.len())?,
                    )
                })?;
                assert_eq!(usize::try_from(output_len).unwrap(), output.len());
                Ok(output)
            }
        }
    }
pub fn mask ( & self , sample : & [ u8 ] ) -> Res < Vec < u8 > > { let mut output = vec ! [ 0_u8 self block_size ( ) ] ; match self { Self :: Aes ( context ) => { let mut output_len : c_int = 0 ; secstatus_to_res ( unsafe { PK11_CipherOp ( * * context . borrow_mut ( ) , output . as_mut_ptr ( ) , & mut output_len , c_int :: try_from ( output . len ( ) ) ? , ( & sample [ .. Self :: SAMPLE_SIZE ] ) . as_ptr ( ) . cast ( ) , c_int :: try_from ( Self :: SAMPLE_SIZE ) . unwrap ( ) , ) } ) ? ; assert_eq ! ( usize try_from ( output_len ) unwrap ( ) output len ( ) ) ; Ok ( output ) } Self :: Chacha ( key ) => { let params : CK_CHACHA20_PARAMS = CK_CHACHA20_PARAMS { pBlockCounter : sample . as_ptr ( ) as * mut u8 , blockCounterBits : 32 , pNonce : ( & sample [ 4 .. Self :: SAMPLE_SIZE ] ) . as_ptr ( ) as * mut _ , ulNonceBits : 96 , } ; let mut output_len : c_uint = 0 ; secstatus_to_res ( unsafe { PK11_Encrypt ( * * key , CK_MECHANISM_TYPE :: from ( CKM_CHACHA20 ) , & Item :: wrap_struct ( & params ) as * const _ as * mut _ , ( & mut output [ .. ] ) . as_mut_ptr ( ) , & mut output_len , c_uint :: try_from ( output . len ( ) ) ? , ( & output [ .. ] ) . as_ptr ( ) , c_uint :: try_from ( output . len ( ) ) ? , ) } ) ? ; assert_eq ! ( usize try_from ( output_len ) unwrap ( ) output len ( ) ) ; Ok ( output ) } } }
Generate a header protection mask for QUIC.
Generate a header protection mask for QUIC .
&self
sample
&[u8]
errors
An error is returned if the NSS functions fail; a sample of the
wrong size is the obvious cause.
An error is returned if the NSS functions fail ; a sample of the wrong size is the obvious cause .
panics
When the mechanism for our key is not supported.
When the mechanism for our key is not supported .