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-11-30: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          560 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      15          560 :         f.debug_struct("RsaInfo")
      16          560 :             .field("key_size", &self.key_size())
      17          560 :             .field("has_public_key", &self.has_public_key())
      18          560 :             .field("has_private_key", &self.has_private_key())
      19          560 :             .finish()
      20          560 :     }
      21              : }
      22              : 
      23              : impl<'a> FromFFI<ffi::PE_RsaInfo> for RsaInfo<'a> {
      24          560 :     fn from_ffi(ptr: cxx::UniquePtr<ffi::PE_RsaInfo>) -> Self {
      25          560 :         RsaInfo {
      26          560 :             ptr,
      27          560 :             _owner: PhantomData,
      28          560 :         }
      29          560 :     }
      30              : }
      31              : 
      32              : impl<'a> RsaInfo<'a> {
      33              :     #[allow(non_snake_case)]
      34              :     /// RSA public modulus
      35          560 :     pub fn N(&self) -> BigUint {
      36          560 :         BigUint::from_bytes_le(self.ptr.N().as_slice())
      37          560 :     }
      38              : 
      39              :     /// RSA public exponent
      40              :     #[allow(non_snake_case)]
      41          560 :     pub fn E(&self) -> BigUint {
      42          560 :         BigUint::from_bytes_le(self.ptr.E().as_slice())
      43          560 :     }
      44              : 
      45              :     #[allow(non_snake_case)]
      46              :     /// RSA private exponent
      47          560 :     pub fn D(&self) -> BigUint {
      48          560 :         BigUint::from_bytes_le(self.ptr.D().as_slice())
      49          560 :     }
      50              : 
      51              :     #[allow(non_snake_case)]
      52              :     /// First prime factor
      53          560 :     pub fn P(&self) -> BigUint {
      54          560 :         BigUint::from_bytes_le(self.ptr.P().as_slice())
      55          560 :     }
      56              :     #[allow(non_snake_case)]
      57              :     /// Second prime factor
      58          560 :     pub fn Q(&self) -> BigUint {
      59          560 :         BigUint::from_bytes_le(self.ptr.Q().as_slice())
      60          560 :     }
      61              : 
      62              :     /// Size of the public modulus (in bits)
      63          560 :     pub fn key_size(&self) -> u32 {
      64          560 :         self.ptr.key_size()
      65          560 :     }
      66              : 
      67              :     /// True if it embeds a public key
      68          560 :     pub fn has_public_key(&self) -> bool {
      69          560 :         self.ptr.has_public_key()
      70          560 :     }
      71              : 
      72              :     /// True if it embeds a private key
      73          560 :     pub fn has_private_key(&self) -> bool {
      74          560 :         self.ptr.has_private_key()
      75          560 :     }
      76              : }
        

Generated by: LCOV version 2.1-1