Skip to content

Commit

Permalink
Fix code formatting with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-albrecht-ibm committed Feb 7, 2024
1 parent 550c2fc commit c03a557
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/blake3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ import { bytes, exists, number, output } from './_assert.js';
import { fromBig } from './_u64.js';
import { BLAKE } from './_blake.js';
import { compress, B2S_IV } from './blake2s.js';
import { Input, u8, u32, toBytes, HashXOF, wrapXOFConstructorWithOpts, isLE, byteSwap32 } from './utils.js';
import {
Input,
u8,
u32,
toBytes,
HashXOF,
wrapXOFConstructorWithOpts,
isLE,
byteSwap32,
} from './utils.js';

// Blake3 is single-option Blake2 with reduced security (round count).

Expand Down
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ export const rotl = (word: number, shift: number) =>
export const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
// The byte swap operation for uint32
export const byteSwap = (word: number) =>
((word << 24) & 0xff000000) | ((word << 8) & 0xff0000) | ((word >>> 8) & 0xff00) | ((word >>> 24) & 0xff);
((word << 24) & 0xff000000) |
((word << 8) & 0xff0000) |
((word >>> 8) & 0xff00) |
((word >>> 24) & 0xff);
// Conditionally byte swap if on a big-endian platform
export const byteSwapIfBE = isLE ? (n: number) => n : (n: number) => byteSwap(n);

Expand Down
4 changes: 2 additions & 2 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ const BYTESWAP_TEST_CASES = [
];

should('byteSwap', () => {
BYTESWAP_TEST_CASES.forEach(test => {
BYTESWAP_TEST_CASES.forEach((test) => {
assert.deepStrictEqual(test.out, byteSwap(test.in));
});
});

should('byteSwapIfBE', () => {
BYTESWAP_TEST_CASES.forEach(test => {
BYTESWAP_TEST_CASES.forEach((test) => {
if (isLE) {
assert.deepStrictEqual(test.in, byteSwapIfBE(test.in));
} else {
Expand Down

0 comments on commit c03a557

Please sign in to comment.