summaryrefslogtreecommitdiffstats
path: root/sq/tests/sq-key-generate.rs
blob: 89f78648fe3bf17f10f30753b23c73ec053ae4b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::time;

use assert_cmd::Command;
use tempfile::TempDir;

use sequoia_openpgp as openpgp;
use openpgp::Result;
use openpgp::cert::prelude::*;
use openpgp::parse::Parse;
use openpgp::policy::StandardPolicy;

mod integration {
    use super::*;

    const P: &StandardPolicy = &StandardPolicy::new();

    #[test]
    fn sq_key_generate_creation_time() -> Result<()>
    {
        // $ date +'%Y%m%dT%H%M%S%z'; date +'%s'
        let iso8601 = "20220120T163236+0100";
        let t = 1642692756;

        let dir = TempDir::new()?;
        let key_pgp = dir.path().join("key.pgp");

        // Build up the command line.
        let mut cmd = Command::cargo_bin("sq")?;
        cmd.args(["key", "generate",
                  "--creation-time", iso8601,
                  "--expires", "never",
                  "--export", &*key_pgp.to_string_lossy()]);

        cmd.assert().success();

        let result = Cert::from_file(key_pgp)?;
        let vc = result.with_policy(P, None)?;

        assert_eq!(vc.primary_key().creation_time(),
                   time::UNIX_EPOCH + time::Duration::new(t, 0));
        assert!(vc.primary_key().key_expiration_time().is_none());

        Ok(())
    }
}