This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from PeculiarVentures/uodate-core
Update core
- Loading branch information
Showing
88 changed files
with
3,760 additions
and
5,230 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -8,8 +8,10 @@ | |
build | ||
|
||
test*.js | ||
/test | ||
|
||
# build | ||
lib | ||
/lib | ||
ts*.json | ||
**/*.map | ||
**/*.map | ||
rollup.config.js |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Core | ||
import * as crypto from "crypto"; | ||
import * as os from "os"; | ||
import * as path from "path"; | ||
import * as core from "webcrypto-core"; | ||
|
||
// Local | ||
import { CryptoKeyStorage } from "./key_storage"; | ||
import { SubtleCrypto } from "./subtle"; | ||
|
||
export interface CryptoOptions { | ||
directory?: string; | ||
} | ||
|
||
/** | ||
* OpenSSL with WebCrypto Interface | ||
*/ | ||
export class Crypto extends core.Crypto { | ||
|
||
public keyStorage: CryptoKeyStorage; | ||
|
||
public subtle = new SubtleCrypto(); | ||
/** | ||
* Constructor | ||
*/ | ||
constructor(options?: CryptoOptions) { | ||
super(); | ||
|
||
this.keyStorage = new CryptoKeyStorage(this, options?.directory ?? path.join(os.homedir(), ".node-webcrypto-ossl")); | ||
} | ||
|
||
/** | ||
* Generates cryptographically random values | ||
* @param array Initialize array | ||
*/ | ||
// Based on: https://github.com/KenanY/get-random-values | ||
public getRandomValues<T extends ArrayBufferView>(array: T): T { | ||
if (ArrayBuffer.isView(array)) { | ||
if (array.byteLength > 65536) { | ||
throw new core.OperationError(`Failed to execute 'getRandomValues' on 'Crypto': The ArrayBufferView's byte length (${array.byteLength}) exceeds the number of bytes of entropy available via this API (65536).`); | ||
} | ||
const bytes = crypto.randomBytes(array.byteLength); | ||
(array as any).set(new (array.constructor as typeof Uint8Array)(bytes.buffer)); | ||
return array; | ||
} else { | ||
throw new core.OperationError(`Failed to execute 'getRandomValues' on 'Crypto': Expected ArrayBufferView for 'array' argument.`); | ||
} | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.