summaryrefslogtreecommitdiffstats
path: root/openpgp/src/packet/signature
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2020-09-17 09:23:41 +0200
committerJustus Winter <justus@sequoia-pgp.org>2020-09-17 09:23:41 +0200
commit629150aad26459592572e1df73a403832e3630cf (patch)
tree7cebe4dc78a3a767881c371289351348cdff92f9 /openpgp/src/packet/signature
parent7c47f04c8c84ba585e59d7257e9114e7e7b10a8c (diff)
Revert "openpgp: Remove SignatureBuilder::set_key_expiration_time."
Diffstat (limited to 'openpgp/src/packet/signature')
-rw-r--r--openpgp/src/packet/signature/subpacket.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs
index 0510acc3..84f3c570 100644
--- a/openpgp/src/packet/signature/subpacket.rs
+++ b/openpgp/src/packet/signature/subpacket.rs
@@ -4564,6 +4564,32 @@ impl signature::SignatureBuilder {
Ok(self)
}
+ /// Sets the value of the Key Expiration Time subpacket.
+ ///
+ /// If `None` is given, any expiration subpacket is removed.
+ pub fn set_key_expiration_time<P, R>(
+ self,
+ key: &Key<P, R>,
+ expiration: Option<time::SystemTime>)
+ -> Result<Self>
+ where P: key::KeyParts,
+ R: key::KeyRole,
+ {
+ if let Some(e) = expiration.map(crate::types::normalize_systemtime) {
+ let ct = key.creation_time();
+ let vp = match e.duration_since(ct) {
+ Ok(v) => v,
+ Err(_) => return Err(Error::InvalidArgument(
+ format!("Expiration time {:?} predates creation time \
+ {:?}", e, ct)).into()),
+ };
+
+ self.set_key_validity_period(Some(vp))
+ } else {
+ self.set_key_validity_period(None)
+ }
+ }
+
/// Sets the Preferred Symmetric Algorithms subpacket.
///
/// Replaces any [Preferred Symmetric Algorithms subpacket] in the