LCOV - code coverage report
Current view: top level - proxy/src/scram - key.rs (source / functions) Coverage Total Hit
Test: 8ac049b474321fdc72ddcb56d7165153a1a900e8.info Lines: 100.0 % 13 13
Test Date: 2023-09-06 10:18:01 Functions: 100.0 % 6 6

            Line data    Source code
       1              : //! Tools for client/server/stored key management.
       2              : 
       3              : /// Faithfully taken from PostgreSQL.
       4              : pub const SCRAM_KEY_LEN: usize = 32;
       5              : 
       6              : /// One of the keys derived from the [password](super::password::SaltedPassword).
       7              : /// We use the same structure for all keys, i.e.
       8              : /// `ClientKey`, `StoredKey`, and `ServerKey`.
       9           30 : #[derive(Default, PartialEq, Eq)]
      10              : #[repr(transparent)]
      11              : pub struct ScramKey {
      12              :     bytes: [u8; SCRAM_KEY_LEN],
      13              : }
      14              : 
      15              : impl ScramKey {
      16           35 :     pub fn sha256(&self) -> Self {
      17           35 :         super::sha256([self.as_ref()]).into()
      18           35 :     }
      19              : 
      20           45 :     pub fn as_bytes(&self) -> [u8; SCRAM_KEY_LEN] {
      21           45 :         self.bytes
      22           45 :     }
      23              : }
      24              : 
      25              : impl From<[u8; SCRAM_KEY_LEN]> for ScramKey {
      26              :     #[inline(always)]
      27          125 :     fn from(bytes: [u8; SCRAM_KEY_LEN]) -> Self {
      28          125 :         Self { bytes }
      29          125 :     }
      30              : }
      31              : 
      32              : impl AsRef<[u8]> for ScramKey {
      33              :     #[inline(always)]
      34           97 :     fn as_ref(&self) -> &[u8] {
      35           97 :         &self.bytes
      36           97 :     }
      37              : }
        

Generated by: LCOV version 2.1-beta