| 1 |
"use strict"; |
| 2 |
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { |
| 3 |
if (k2 === undefined) k2 = k; |
| 4 |
var desc = Object.getOwnPropertyDescriptor(m, k); |
| 5 |
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { |
| 6 |
desc = { enumerable: true, get: function() { return m[k]; } }; |
| 7 |
} |
| 8 |
Object.defineProperty(o, k2, desc); |
| 9 |
}) : (function(o, m, k, k2) { |
| 10 |
if (k2 === undefined) k2 = k; |
| 11 |
o[k2] = m[k]; |
| 12 |
})); |
| 13 |
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { |
| 14 |
Object.defineProperty(o, "default", { enumerable: true, value: v }); |
| 15 |
}) : function(o, v) { |
| 16 |
o["default"] = v; |
| 17 |
}); |
| 18 |
var __importStar = (this && this.__importStar) || (function () { |
| 19 |
var ownKeys = function(o) { |
| 20 |
ownKeys = Object.getOwnPropertyNames || function (o) { |
| 21 |
var ar = []; |
| 22 |
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; |
| 23 |
return ar; |
| 24 |
}; |
| 25 |
return ownKeys(o); |
| 26 |
}; |
| 27 |
return function (mod) { |
| 28 |
if (mod && mod.__esModule) return mod; |
| 29 |
var result = {}; |
| 30 |
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); |
| 31 |
__setModuleDefault(result, mod); |
| 32 |
return result; |
| 33 |
}; |
| 34 |
})(); |
| 35 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 36 |
exports.TSTInfo = void 0; |
| 37 |
const crypto = __importStar(require("../crypto")); |
| 38 |
const oid_1 = require("../oid"); |
| 39 |
const error_1 = require("./error"); |
| 40 |
class TSTInfo { |
| 41 |
root; |
| 42 |
constructor(asn1) { |
| 43 |
this.root = asn1; |
| 44 |
} |
| 45 |
get version() { |
| 46 |
return this.root.subs[0].toInteger(); |
| 47 |
} |
| 48 |
get genTime() { |
| 49 |
return this.root.subs[4].toDate(); |
| 50 |
} |
| 51 |
get messageImprintHashAlgorithm() { |
| 52 |
const oid = this.messageImprintObj.subs[0].subs[0].toOID(); |
| 53 |
return oid_1.SHA2_HASH_ALGOS[oid]; |
| 54 |
} |
| 55 |
get messageImprintHashedMessage() { |
| 56 |
return this.messageImprintObj.subs[1].value; |
| 57 |
} |
| 58 |
get raw() { |
| 59 |
return this.root.toDER(); |
| 60 |
} |
| 61 |
verify(data) { |
| 62 |
const digest = crypto.digest(this.messageImprintHashAlgorithm, data); |
| 63 |
if (!crypto.bufferEqual(digest, this.messageImprintHashedMessage)) { |
| 64 |
throw new error_1.RFC3161TimestampVerificationError('message imprint does not match artifact'); |
| 65 |
} |
| 66 |
} |
| 67 |
// https://www.rfc-editor.org/rfc/rfc3161#section-2.4.2 |
| 68 |
get messageImprintObj() { |
| 69 |
return this.root.subs[2]; |
| 70 |
} |
| 71 |
} |
| 72 |
exports.TSTInfo = TSTInfo; |