Add getExpirationTime method to Key and SubKey
This commit is contained in:
parent
ce1239f4e8
commit
a595d683a9
40
src/key.js
40
src/key.js
|
@ -440,12 +440,42 @@ Key.prototype.verifyPrimaryKey = function() {
|
||||||
}
|
}
|
||||||
// check V4 expiration time
|
// check V4 expiration time
|
||||||
if (this.primaryKey.version == 4 && primaryUser.selfCertificate.keyNeverExpires === false &&
|
if (this.primaryKey.version == 4 && primaryUser.selfCertificate.keyNeverExpires === false &&
|
||||||
Date.now() > (primaryUser.selfCertificate.created.getTime() + primaryUser.selfCertificate.keyExpirationTime*1000)) {
|
Date.now() > (this.primaryKey.created.getTime() + primaryUser.selfCertificate.keyExpirationTime*1000)) {
|
||||||
return enums.keyStatus.expired;
|
return enums.keyStatus.expired;
|
||||||
}
|
}
|
||||||
return enums.keyStatus.valid;
|
return enums.keyStatus.valid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the expiration time of the primary key or null if key does not expire
|
||||||
|
* @return {Date|null}
|
||||||
|
*/
|
||||||
|
Key.prototype.getExpirationTime = function() {
|
||||||
|
if (this.primaryKey.version == 3) {
|
||||||
|
return getExpirationTime(this.primaryKey);
|
||||||
|
}
|
||||||
|
if (this.primaryKey.version == 4) {
|
||||||
|
var primaryUser = this.getPrimaryUser();
|
||||||
|
if (!primaryUser) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return getExpirationTime(this.primaryKey, primaryUser.selfCertificate);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function getExpirationTime(keyPacket, selfCertificate) {
|
||||||
|
// check V3 expiration time
|
||||||
|
if (keyPacket.version == 3 && keyPacket.expirationTimeV3 !== 0) {
|
||||||
|
return new Date(keyPacket.created.getTime() + keyPacket.expirationTimeV3*24*3600*1000);
|
||||||
|
}
|
||||||
|
// check V4 expiration time
|
||||||
|
if (this.primaryKey.version == 4 && selfCertificate.keyNeverExpires === false) {
|
||||||
|
return new Date(keyPacket.created.getTime() + selfCertificate.keyExpirationTime*1000);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns primary user and most significant (latest valid) self signature
|
* Returns primary user and most significant (latest valid) self signature
|
||||||
* - if multiple users are marked as primary users returns the one with the latest self signature
|
* - if multiple users are marked as primary users returns the one with the latest self signature
|
||||||
|
@ -668,6 +698,14 @@ SubKey.prototype.verify = function(primaryKey) {
|
||||||
return enums.keyStatus.valid;
|
return enums.keyStatus.valid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the expiration time of the subkey or null if key does not expire
|
||||||
|
* @return {Date|null}
|
||||||
|
*/
|
||||||
|
SubKey.prototype.getExpirationTime = function() {
|
||||||
|
return getExpirationTime(this.subKey, this.bindingSignature);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads an OpenPGP armored text and returns one or multiple key objects
|
* Reads an OpenPGP armored text and returns one or multiple key objects
|
||||||
* @param {String} armoredText text to be parsed
|
* @param {String} armoredText text to be parsed
|
||||||
|
|
Loading…
Reference in New Issue
Block a user