Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(permanentid): replace sha256 by md5(30)+sha1(30) #77

Merged
merged 1 commit into from
Jan 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
replace hash-sha256 by md5+sha1
  • Loading branch information
jdevost committed Jan 20, 2022
commit f4da87ca43a9a02d8aa41ec937b2ec754bfda3eb
7 changes: 7 additions & 0 deletions src/documentBuilder.spec.ts
Original file line number Diff line number Diff line change
@@ -81,6 +81,13 @@ describe('DocumentBuilder', () => {
expect(docBuilder.withPermanentId('id').marshal().permanentId).toBe('id');
});

it('should generate permanentid', () => {
docBuilder = new DocumentBuilder('https://foo.com', 'bar');
expect(docBuilder.marshal().permanentId).toBe(
'aa2e0510b66edff7f05e2b30d4f1b3a4b5481c06b69f41751c54675c5afb'
);
});

it('throws when adding a reserved key name metadata', () => {
const theseShouldThrow = [
'compressedBinaryData',
4 changes: 3 additions & 1 deletion src/documentBuilder.ts
Original file line number Diff line number Diff line change
@@ -268,7 +268,9 @@ export class DocumentBuilder {
}

private generatePermanentId() {
return createHash('sha256').update(this.doc.uri).digest('hex');
const md5: string = createHash('md5').update(this.doc.uri).digest('hex');
const sha1: string = createHash('sha1').update(this.doc.uri).digest('hex');
return md5.substring(0, 30) + sha1.substring(0, 30);
}

private validateDateAndReturnValidDate(d: Date | string | number) {