-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
56 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ export type { | |
|
||
export { | ||
AeadId, | ||
BaseError, | ||
DecapError, | ||
DeriveKeyPairError, | ||
DeserializeError, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
import { BaseError } from "@hpke/core"; | ||
|
||
/** | ||
* The base error class of kyber. | ||
*/ | ||
export class KyberError extends BaseError {} | ||
export class KyberError extends Error { | ||
public constructor(e: unknown) { | ||
let message: string; | ||
|
||
if (e instanceof Error) { | ||
message = e.message; | ||
} else if (typeof e === "string") { | ||
message = e; | ||
} else { | ||
message = ""; | ||
} | ||
super(message); | ||
|
||
this.name = this.constructor.name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { assertEquals } from "@std/assert"; | ||
|
||
import { describe, it } from "@std/testing/bdd"; | ||
|
||
import { KyberError } from "../src/kyber/errors.ts"; | ||
|
||
describe("KyberError", () => { | ||
describe("constructor with neigher string or Error", () => { | ||
it("should have valid name and message", () => { | ||
const err = new KyberError(undefined); | ||
|
||
// assert | ||
assertEquals(err.name, "KyberError"); | ||
assertEquals(err.message, ""); | ||
}); | ||
}); | ||
|
||
describe("constructor with string", () => { | ||
it("should have valid name and message", () => { | ||
const err = new KyberError("failed"); | ||
|
||
// assert | ||
assertEquals(err.name, "KyberError"); | ||
assertEquals(err.message, "failed"); | ||
}); | ||
}); | ||
|
||
describe("constructor with another Error", () => { | ||
it("should have valid name and message", () => { | ||
const origin = new Error("failed"); | ||
const err = new KyberError(origin); | ||
|
||
// assert | ||
assertEquals(err.name, "KyberError"); | ||
assertEquals(err.message, "failed"); | ||
}); | ||
}); | ||
}); |