LCOV - code coverage report
Current view: top level - src/pe/signature - rsa_info.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 100.0 % 37 37
Test Date: 2024-10-27:00:00:00 Functions: 100.0 % 10 10

            Line data    Source code
       1              : use lief_ffi as ffi;
       2              : use num_bigint::BigUint;
       3              : 
       4              : use crate::common::FromFFI;
       5              : use std::marker::PhantomData;
       6              : 
       7              : /// Structure that wraps an RSA key
       8              : pub struct RsaInfo<'a> {
       9              :     ptr: cxx::UniquePtr<ffi::PE_RsaInfo>,
      10              :     _owner: PhantomData<&'a ()>,
      11              : }
      12              : 
      13              : impl std::fmt::Debug for RsaInfo<'_> {
      14          448 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      15          448 :         f.debug_struct("RsaInfo")
      16          448 :             .field("key_size", &self.key_size())
      17          448 :             .field("has_public_key", &self.has_public_key())
      18          448 :             .field("has_private_key", &self.has_private_key())
      19          448 :             .finish()
      20          448 :     }
      21              : }
      22              : 
      23              : impl<'a> FromFFI<ffi::PE_RsaInfo> for RsaInfo<'a> {
      24          448 :     fn from_ffi(ptr: cxx::UniquePtr<ffi::PE_RsaInfo>) -> Self {
      25          448 :         RsaInfo {
      26          448 :             ptr,
      27          448 :             _owner: PhantomData,
      28          448 :         }
      29          448 :     }
      30              : }
      31              : 
      32              : impl<'a> RsaInfo<'a> {
      33              :     #[allow(non_snake_case)]
      34              :     /// RSA public modulus
      35          448 :     pub fn N(&self) -> BigUint {
      36          448 :         BigUint::from_bytes_le(self.ptr.N().as_slice())
      37          448 :     }
      38              : 
      39              :     /// RSA public exponent
      40              :     #[allow(non_snake_case)]
      41          448 :     pub fn E(&self) -> BigUint {
      42          448 :         BigUint::from_bytes_le(self.ptr.E().as_slice())
      43          448 :     }
      44              : 
      45              :     #[allow(non_snake_case)]
      46              :     /// RSA private exponent
      47          448 :     pub fn D(&self) -> BigUint {
      48          448 :         BigUint::from_bytes_le(self.ptr.D().as_slice())
      49          448 :     }
      50              : 
      51              :     #[allow(non_snake_case)]
      52              :     /// First prime factor
      53          448 :     pub fn P(&self) -> BigUint {
      54          448 :         BigUint::from_bytes_le(self.ptr.P().as_slice())
      55          448 :     }
      56              :     #[allow(non_snake_case)]
      57              :     /// Second prime factor
      58          448 :     pub fn Q(&self) -> BigUint {
      59          448 :         BigUint::from_bytes_le(self.ptr.Q().as_slice())
      60          448 :     }
      61              : 
      62              :     /// Size of the public modulus (in bits)
      63          448 :     pub fn key_size(&self) -> u32 {
      64          448 :         self.ptr.key_size()
      65          448 :     }
      66              : 
      67              :     /// True if it embeds a public key
      68          448 :     pub fn has_public_key(&self) -> bool {
      69          448 :         self.ptr.has_public_key()
      70          448 :     }
      71              : 
      72              :     /// True if it embeds a private key
      73          448 :     pub fn has_private_key(&self) -> bool {
      74          448 :         self.ptr.has_private_key()
      75          448 :     }
      76              : }
        

Generated by: LCOV version 2.1-1