1 // Copyright 2015-2019 Brian Smith. 2 // 3 // Permission to use, copy, modify, and/or distribute this software for any 4 // purpose with or without fee is hereby granted, provided that the above 5 // copyright notice and this permission notice appear in all copies. 6 // 7 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES 8 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 10 // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 15 //! RSA OAEP decryption. 16 17 use super::RsaKeyPair; 18 use crate::{error, rsa::padding}; 19 use alloc::boxed::Box; 20 21 impl RsaKeyPair { 22 /// OAEP decrypts `ciphertext`, returning the plaintext. decrypt_oaep_bytes_less_safe( &self, encoding: &'static padding::OaepEncoding, ciphertext: &[u8], ) -> Result<Box<[u8]>, error::Unspecified>23 pub fn decrypt_oaep_bytes_less_safe( 24 &self, 25 encoding: &'static padding::OaepEncoding, 26 ciphertext: &[u8], 27 ) -> Result<Box<[u8]>, error::Unspecified> { 28 self.rsa_private(ciphertext, |padded_buffer| { 29 let plaintext = 30 padding::oaep_decode(encoding, padded_buffer, self.public().n().len_bits())?; 31 Ok(plaintext.into()) 32 }) 33 } 34 } 35