Skip to content

Commit

Permalink
🤖 🎨 Autoformat
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Flynn <pflynn@virtru.com>
  • Loading branch information
pflynn-virtru committed Aug 15, 2024
1 parent d4b53d0 commit 8262fbd
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/src/nanotdf/models/ResourceLocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,25 @@ export default class ResourceLocator {
// protocol and identifier byte
const protocolIdentifierByte = new Uint8Array(1);
if (protocol.toLowerCase() == 'http') {
protocolIdentifierByte[0] = protocolIdentifierByte[0] & 0x0F;
protocolIdentifierByte[0] = protocolIdentifierByte[0] & 0x0f;
} else if (protocol.toLowerCase() == 'https') {
protocolIdentifierByte[0] = (protocolIdentifierByte[0] & 0x0F) | 0b0010;
protocolIdentifierByte[0] = (protocolIdentifierByte[0] & 0x0f) | 0b0010;
} else {
throw new Error('Resource locator protocol is not supported.');
}
if (identifierLength === 0) {
protocolIdentifierByte[0] = (protocolIdentifierByte[0] & 0xF0) | 0b0000;
protocolIdentifierByte[0] = (protocolIdentifierByte[0] & 0xf0) | 0b0000;
} else if (identifierLength <= 2) {
protocolIdentifierByte[0] = (protocolIdentifierByte[0] & 0xF0) | 0b0010;
protocolIdentifierByte[0] = (protocolIdentifierByte[0] & 0xf0) | 0b0010;
identifierPaddedLength = ResourceLocatorIdentifierEnum.TwoBytes.valueOf();
} else if (identifierLength <= 8) {
protocolIdentifierByte[0] = (protocolIdentifierByte[0] & 0xF0) | 0b0100;
protocolIdentifierByte[0] = (protocolIdentifierByte[0] & 0xf0) | 0b0100;
identifierPaddedLength = ResourceLocatorIdentifierEnum.EightBytes.valueOf();
} else if (identifierLength <= 32) {
protocolIdentifierByte[0] = (protocolIdentifierByte[0] & 0xF0) | 0b1000;
protocolIdentifierByte[0] = (protocolIdentifierByte[0] & 0xf0) | 0b1000;
identifierPaddedLength = ResourceLocatorIdentifierEnum.ThirtyTwoBytes.valueOf();
} else {
throw new Error("Unsupported identifier length: " + identifierLength);
throw new Error('Unsupported identifier length: ' + identifierLength);
}
// Buffer to hold the protocol, length of body, body, and identifierPadded
const buffer = new Uint8Array(1 + 1 + bodyLength + identifierPaddedLength);
Expand All @@ -66,7 +66,9 @@ export default class ResourceLocator {
// add padded identifier
if (identifierPaddedLength > 0) {
const identifierArray = new Uint8Array(identifierPaddedLength);
const encodedIdentifier = new TextEncoder().encode(identifier).subarray(0, identifierPaddedLength);
const encodedIdentifier = new TextEncoder()
.encode(identifier)
.subarray(0, identifierPaddedLength);
identifierArray.set(encodedIdentifier);
buffer.set(identifierArray, 2 + bodyLength);
}
Expand Down Expand Up @@ -109,7 +111,10 @@ export default class ResourceLocator {
break;
}
this.offset =
ResourceLocator.PROTOCOL_LENGTH + ResourceLocator.LENGTH_LENGTH + this.lengthOfBody + this.identifierType.valueOf();
ResourceLocator.PROTOCOL_LENGTH +
ResourceLocator.LENGTH_LENGTH +
this.lengthOfBody +
this.identifierType.valueOf();
}

/**
Expand Down

0 comments on commit 8262fbd

Please sign in to comment.