Skip to content

Commit

Permalink
Remove unused code from HMAC implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrence-forooghian committed Jun 7, 2023
1 parent 3845a19 commit 2eae3df
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/platform/web/lib/util/bufferutils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import WordArray from 'crypto-js/build/lib-typedarrays';
import Platform from 'common/platform';
import IBufferUtils from 'common/types/IBufferUtils';
import { sign as hmacSha256 } from './hmac-sha256';
import { hmac as hmacSha256 } from './hmac-sha256';

/* Most BufferUtils methods that return a binary object return an ArrayBuffer
* The exception is toBuffer, which returns a Uint8Array (and won't work on
Expand Down
19 changes: 1 addition & 18 deletions src/platform/web/lib/util/hmac-sha256.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function sha256(data: Uint8Array) {
);
}

function hmac(key: Uint8Array, data: Uint8Array) {
export function hmac(key: Uint8Array, data: Uint8Array) {
if (key.length > 64) key = sha256(key);

if (key.length < 64) {
Expand Down Expand Up @@ -215,20 +215,3 @@ function hmac(key: Uint8Array, data: Uint8Array) {
// Hash the previous message
return sha256(result);
}

// Convert a string to a Uint8Array, SHA-256 it, and convert back to string
const encoder = new TextEncoder();

export function sign(inputKey: string | Uint8Array, inputData: string | Uint8Array) {
const key = typeof inputKey === 'string' ? encoder.encode(inputKey) : inputKey;
const data = typeof inputData === 'string' ? encoder.encode(inputData) : inputData;
return hmac(key, data);
}

export function hash(str: string) {
return hex(sha256(encoder.encode(str)));
}

export function hex(bin: Uint8Array) {
return bin.reduce((acc, val) => acc + ('00' + val.toString(16)).substr(-2), '');
}

0 comments on commit 2eae3df

Please sign in to comment.