• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

namib-project / dcaf-rs / 11935120896

20 Nov 2024 02:11PM UTC coverage: 86.555% (+1.3%) from 85.242%
11935120896

Pull #27

github

web-flow
Merge d2b3d706b into 383248641
Pull Request #27: ci: update grcov to latest stable version

6116 of 7066 relevant lines covered (86.56%)

167.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/src/token/cose/crypto_impl/rustcrypto/encrypt/aes_gcm.rs
1
/*
2
 * Copyright (c) 2024 The NAMIB Project Developers.
3
 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4
 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5
 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6
 * option. This file may not be copied, modified, or distributed
7
 * except according to those terms.
8
 *
9
 * SPDX-License-Identifier: MIT OR Apache-2.0
10
 */
11
use aes::Aes192;
12
use aes_gcm::{Aes128Gcm, Aes256Gcm, AesGcm};
13
use coset::{iana, Algorithm};
14
use rand::CryptoRng;
15
use rand::RngCore;
16
use typenum::consts::U12;
17

18
use crate::error::CoseCipherError;
19
use crate::token::cose::{CoseSymmetricKey, CryptoBackend};
20

21
use super::RustCryptoContext;
22
use alloc::vec::Vec;
23

24
impl<RNG: RngCore + CryptoRng> RustCryptoContext<RNG> {
25
    /// Perform an AES-GCM encryption operation on `plaintext` and the additional authenticated
26
    /// data `aad` using the given `iv` and `key` with the given `algorithm` variant of AES-GCM.
27
    pub(super) fn encrypt_aes_gcm(
35✔
28
        algorithm: iana::Algorithm,
35✔
29
        key: &CoseSymmetricKey<'_, <Self as CryptoBackend>::Error>,
35✔
30
        plaintext: &[u8],
35✔
31
        aad: &[u8],
35✔
32
        iv: &[u8],
35✔
33
    ) -> Result<Vec<u8>, CoseCipherError<<Self as CryptoBackend>::Error>> {
35✔
34
        match algorithm {
35✔
35
            iana::Algorithm::A128GCM => Self::encrypt_aead::<Aes128Gcm>(key, plaintext, aad, iv),
28✔
36
            iana::Algorithm::A192GCM => {
37
                Self::encrypt_aead::<AesGcm<Aes192, U12>>(key, plaintext, aad, iv)
5✔
38
            }
39
            iana::Algorithm::A256GCM => Self::encrypt_aead::<Aes256Gcm>(key, plaintext, aad, iv),
2✔
40
            a => Err(CoseCipherError::UnsupportedAlgorithm(Algorithm::Assigned(
×
41
                a,
×
42
            ))),
×
43
        }
44
    }
35✔
45

46
    /// Perform an AES-GCM decryption operation on `ciphertext` and the additional authenticated
47
    /// data `aad` using the given `iv` and `key` with the given `algorithm` variant of AES-GCM.
48
    pub(super) fn decrypt_aes_gcm(
56✔
49
        algorithm: iana::Algorithm,
56✔
50
        key: &CoseSymmetricKey<'_, <Self as CryptoBackend>::Error>,
56✔
51
        ciphertext_with_tag: &[u8],
56✔
52
        aad: &[u8],
56✔
53
        iv: &[u8],
56✔
54
    ) -> Result<Vec<u8>, CoseCipherError<<Self as CryptoBackend>::Error>> {
56✔
55
        match algorithm {
56✔
56
            iana::Algorithm::A128GCM => {
57
                Self::decrypt_aead::<Aes128Gcm>(key, ciphertext_with_tag, aad, iv)
42✔
58
            }
59
            iana::Algorithm::A192GCM => {
60
                Self::decrypt_aead::<AesGcm<Aes192, U12>>(key, ciphertext_with_tag, aad, iv)
10✔
61
            }
62
            iana::Algorithm::A256GCM => {
63
                Self::decrypt_aead::<Aes256Gcm>(key, ciphertext_with_tag, aad, iv)
4✔
64
            }
65
            a => Err(CoseCipherError::UnsupportedAlgorithm(Algorithm::Assigned(
×
66
                a,
×
67
            ))),
×
68
        }
69
    }
56✔
70
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc