add exception for sessionSecret
This commit is contained in:
parent
8a3683d2e5
commit
2e6ce88e80
7
mod.ts
7
mod.ts
|
@ -6,6 +6,7 @@ import * as path from "https://deno.land/std@0.185.0/path/mod.ts";
|
|||
import * as cookie from "https://deno.land/std@0.185.0/http/cookie.ts";
|
||||
import { Aes } from "https://deno.land/x/crypto/aes.ts";
|
||||
import { Cbc, Padding } from "https://deno.land/x/crypto/block-modes.ts";
|
||||
import { cryptoRandomString } from "https://deno.land/x/crypto_random_string@1.0.0/mod.ts";
|
||||
|
||||
type HTTPServerOptions = {
|
||||
port: number;
|
||||
|
@ -61,6 +62,12 @@ export class HTTPServer {
|
|||
settings?: HTTPServerOptions;
|
||||
|
||||
async listen(options: HTTPServerOptions) {
|
||||
if (options.sessionSecret) {
|
||||
if (![16, 24, 32].includes(options.sessionSecret.length)) {
|
||||
const randomString = cryptoRandomString({ length: 32 });
|
||||
throw new Error("\nInvalid key size (must be either 16, 24 or 32 bytes)\nHere is a pregenerated key: " + randomString);
|
||||
}
|
||||
}
|
||||
this.settings = options;
|
||||
this.server = Deno.listen({
|
||||
port: options.port,
|
||||
|
|
Reference in New Issue
Block a user