Skip to content

Commit

Permalink
Merge pull request #431 from dajiaji/add-base64-url-to-bytes
Browse files Browse the repository at this point in the history
Disclose base64UrlToBytes on @hpke/common.
  • Loading branch information
dajiaji authored Oct 13, 2024
2 parents 7ec3ee7 + 46227ef commit 7daa676
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 20 deletions.
1 change: 1 addition & 0 deletions packages/common/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export { SUITE_ID_HEADER_KEM } from "./src/interfaces/kemInterface.ts";
export { EMPTY, INPUT_LENGTH_LIMIT, MINIMUM_PSK_LENGTH } from "./src/consts.ts";

export {
base64UrlToBytes,
concat,
hexToBytes,
i2Osp,
Expand Down
11 changes: 1 addition & 10 deletions packages/dhkem-x25519/src/x25519.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { x25519 } from "@noble/curves/ed25519";
import type { DhkemPrimitives, KdfInterface } from "@hpke/common";

import {
base64UrlToBytes,
DeriveKeyPairError,
DeserializeError,
EMPTY,
Expand All @@ -16,16 +17,6 @@ import {

const ALG_NAME = "X25519";

function base64UrlToBytes(v: string): Uint8Array {
const base64 = v.replace(/-/g, "+").replace(/_/g, "/");
const byteString = atob(base64);
const ret = new Uint8Array(byteString.length);
for (let i = 0; i < byteString.length; i++) {
ret[i] = byteString.charCodeAt(i);
}
return ret;
}

export class X25519 implements DhkemPrimitives {
private _hkdf: KdfInterface;
private _nPk: number;
Expand Down
11 changes: 1 addition & 10 deletions packages/dhkem-x448/src/x448.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { x448 } from "@noble/curves/ed448";
import type { DhkemPrimitives, KdfInterface } from "@hpke/common";

import {
base64UrlToBytes,
DeriveKeyPairError,
DeserializeError,
EMPTY,
Expand All @@ -16,16 +17,6 @@ import {

const ALG_NAME = "X448";

function base64UrlToBytes(v: string): Uint8Array {
const base64 = v.replace(/-/g, "+").replace(/_/g, "/");
const byteString = atob(base64);
const ret = new Uint8Array(byteString.length);
for (let i = 0; i < byteString.length; i++) {
ret[i] = byteString.charCodeAt(i);
}
return ret;
}

export class X448 implements DhkemPrimitives {
private _hkdf: KdfInterface;
private _nPk: number;
Expand Down

0 comments on commit 7daa676

Please sign in to comment.