Skip to content

Commit

Permalink
setSignature fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cfranc0 committed Dec 14, 2023
1 parent 9d5fa7f commit e9f9d48
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xevolab/timestamping-token",
"version": "1.1.0",
"version": "1.1.1",
"description": "Time Stamping Authority (TSA) implementation.",
"keywords": [
"Timestamping Authority",
Expand Down
19 changes: 12 additions & 7 deletions src/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Author : Francesco
* Created at: 2023-12-09 17:52
* Edited by : Francesco
* Edited at : 2023-12-13 20:41
* Edited at : 2023-12-14 15:43
*
* Copyright (c) 2023 Xevolab S.R.L.
*/
Expand Down Expand Up @@ -30,6 +30,7 @@ export class TimeStampResp {
public signingTime!: Date;
public serialNumber!: Buffer;
public buffer!: Buffer;
private asn1!: asn1js.Sequence;

// Signature
public payloadDigest?: Buffer;
Expand Down Expand Up @@ -552,19 +553,23 @@ export class TimeStampResp {
})]
}));

this.asn1 = TimeStampResp;
return Buffer.from(TimeStampResp.toBER(false));
}

public setSignature(signature: Buffer) {
const tmp = asn1js.fromBER(this.buffer);
// @ts-ignore
let ref = tmp.result.valueBlock.value[1].valueBlock.value[1].valueBlock.value[0].valueBlock.value;
ref = ref.at(-1).valueBlock.value[0].valueBlock.value.at(-1);
console.log(Buffer.from(ref.valueBlock.valueHexView));
const index1 = this.asn1.valueBlock.value[1].valueBlock.value[1].valueBlock.value[0].valueBlock.value.length - 1;
// @ts-ignore
const index2 = this.asn1.valueBlock.value[1].valueBlock.value[1].valueBlock.value[0].valueBlock.value[index1].valueBlock.value[0].valueBlock.value.length - 1;

// @ts-ignore
this.asn1.valueBlock.value[1].valueBlock.value[1].valueBlock.value[0].valueBlock.value[index1].valueBlock.value[0].valueBlock.value[index2] = new asn1js.OctetString({
valueHex: signature
});

ref.valueBlock.valueHexView = signature
this.buffer = Buffer.from(this.asn1.toBER(false));

this.buffer = Buffer.from(tmp.result.toBER(false));
}

}
Expand Down

0 comments on commit e9f9d48

Please sign in to comment.