LCOV - code coverage report
Current view: top level - src/pe/signature - signer_info.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 100.0 % 65 65
Test Date: 2024-11-30:00:00:00 Functions: 100.0 % 15 15

            Line data    Source code
       1              : use std::marker::PhantomData;
       2              : 
       3              : use super::attributes::Attribute;
       4              : use super::X509;
       5              : use crate::pe::Algorithms;
       6              : use crate::to_slice;
       7              : use crate::common::{FromFFI, into_optional};
       8              : use crate::declare_iterator;
       9              : use lief_ffi as ffi;
      10              : 
      11              : /// SignerInfo as described in the [RFC 2315](https://tools.ietf.org/html/rfc2315#section-9.2)
      12              : pub struct SignerInfo<'a> {
      13              :     ptr: cxx::UniquePtr<ffi::PE_SignerInfo>,
      14              :     _owner: PhantomData<&'a ()>, // Can be own by Signature or PKCS9CounterSignature
      15              : }
      16              : 
      17              : impl std::fmt::Debug for SignerInfo<'_> {
      18          190 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      19          190 :         f.debug_struct("SignerInfo")
      20          190 :             .field("version", &self.version())
      21          190 :             .field("issuer", &self.issuer())
      22          190 :             .field("digest_algorithm", &self.digest_algorithm())
      23          190 :             .field("encryption_algorithm", &self.encryption_algorithm())
      24          190 :             .finish()
      25          190 :     }
      26              : }
      27              : 
      28              : impl<'a> FromFFI<ffi::PE_SignerInfo> for SignerInfo<'a> {
      29          240 :     fn from_ffi(ptr: cxx::UniquePtr<ffi::PE_SignerInfo>) -> Self {
      30          240 :         SignerInfo {
      31          240 :             ptr,
      32          240 :             _owner: PhantomData,
      33          240 :         }
      34          240 :     }
      35              : }
      36              : 
      37              : impl<'a> SignerInfo<'a> {
      38              :     /// Should be 1
      39          190 :     pub fn version(&self) -> u32 {
      40          190 :         self.ptr.version()
      41          190 :     }
      42              : 
      43              :     /// Return the [`X509::issuer`] used by this signer
      44          190 :     pub fn issuer(&self) -> String {
      45          190 :         self.ptr.issuer().to_string()
      46          190 :     }
      47              : 
      48              :     /// Algorithm used to hash the file.
      49          190 :     pub fn digest_algorithm(&self) -> Algorithms {
      50          190 :         Algorithms::from(self.ptr.digest_algorithm())
      51          190 :     }
      52              : 
      53              :     /// Return the (public-key) algorithm used to encrypt the signature
      54          190 :     pub fn encryption_algorithm(&self) -> Algorithms {
      55          190 :         Algorithms::from(self.ptr.encryption_algorithm())
      56          190 :     }
      57              : 
      58              :     /// Return the serial number associated with the x509 certificate
      59              :     /// used by this signer.
      60          190 :     pub fn serial_number(&self) -> &[u8] {
      61          190 :         to_slice!(self.ptr.serial_number());
      62          190 :     }
      63              : 
      64              :     /// Return the signature created by the signing certificate's private key
      65          190 :     pub fn encrypted_digest(&self) -> Vec<u8> {
      66          190 :         Vec::from(self.ptr.encrypted_digest().as_slice())
      67          190 :     }
      68              : 
      69              :     /// [`X509`] certificate used by this signer.
      70          190 :     pub fn cert(&self) -> Option<X509> {
      71          190 :         into_optional(self.ptr.cert())
      72          190 :     }
      73              : 
      74              :     /// Iterator over the **authenticated** [`Attribute`]
      75          240 :     pub fn authenticated_attributes(&self) -> AuthenticatedAttributes {
      76          240 :         AuthenticatedAttributes::new(self.ptr.authenticated_attributes())
      77          240 :     }
      78              : 
      79              :     /// Iterator over the **unauthenticated** [`Attribute`]
      80          240 :     pub fn unauthenticated_attributes(&self) -> UnAuthenticatedAttributes {
      81          240 :         UnAuthenticatedAttributes::new(self.ptr.unauthenticated_attributes())
      82          240 :     }
      83              : 
      84              :     /// Raw blob that is signed by the signer certificate
      85           50 :     pub fn raw_auth_data(&self) -> &[u8] {
      86           50 :         to_slice!(self.ptr.raw_auth_data());
      87           50 :     }
      88              : }
      89              : 
      90          130 : declare_iterator!(
      91          130 :     Signers,
      92          130 :     SignerInfo<'a>,
      93          130 :     ffi::PE_SignerInfo,
      94          130 :     ffi::PE_Signature,
      95          130 :     ffi::PE_Signature_it_signers
      96          130 : );
      97          880 : declare_iterator!(
      98          880 :     AuthenticatedAttributes,
      99          880 :     Attribute<'a>,
     100          880 :     ffi::PE_Attribute,
     101          880 :     ffi::PE_SignerInfo,
     102          880 :     ffi::PE_SignerInfo_it_authenticated_attributes
     103          880 : );
     104          140 : declare_iterator!(
     105          140 :     UnAuthenticatedAttributes,
     106          140 :     Attribute<'a>,
     107          140 :     ffi::PE_Attribute,
     108          140 :     ffi::PE_SignerInfo,
     109          140 :     ffi::PE_SignerInfo_it_unauthenticated_attributes
     110          140 : );
        

Generated by: LCOV version 2.1-1