-
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.
Merge pull request #199 from dajiaji/add-common-server-for-testing
Add common server for testing.
- Loading branch information
Showing
10 changed files
with
107 additions
and
165 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
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 |
---|---|---|
@@ -1,44 +1,8 @@ | ||
import * as hpke from "./hpke.js"; | ||
import { testServer } from "../../server.js"; | ||
|
||
export default { | ||
port: 3000, | ||
async fetch(request) { | ||
const url = new URL(request.url); | ||
if (url.pathname !== "/test") { | ||
return new Response("ng: invalid path"); | ||
} | ||
const params = url.searchParams; | ||
const kemStr = params.get("kem"); | ||
const kdfStr = params.get("kdf"); | ||
const aeadStr = params.get("aead"); | ||
if (kemStr === null || kdfStr === null || aeadStr === null) { | ||
return new Response("ng: invalid params"); | ||
} | ||
const kem = Number.parseInt(kemStr); | ||
const kdf = Number.parseInt(kdfStr); | ||
const aead = Number.parseInt(aeadStr); | ||
if (Number.isNaN(kem) || Number.isNaN(kdf) || Number.isNaN(aead)) { | ||
return new Response("ng: invalid params"); | ||
} | ||
|
||
try { | ||
const suite = new hpke.CipherSuite({ kem: kem, kdf: kdf, aead: aead }); | ||
const rkp = await suite.generateKeyPair(); | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey, | ||
}); | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp, | ||
enc: sender.enc, | ||
}); | ||
const ct = await sender.seal(new TextEncoder().encode("hello world!")); | ||
const pt = await recipient.open(ct); | ||
if ("hello world!" !== new TextDecoder().decode(pt)) { | ||
return new Response("ng"); | ||
} | ||
} catch (e) { | ||
return new Response("ng: " + e.message); | ||
} | ||
return new Response("ok"); | ||
return await testServer(request); | ||
}, | ||
}; |
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,43 +1,7 @@ | ||
import * as hpke from "./hpke.js"; | ||
import { testServer } from "../../server.js"; | ||
|
||
export default { | ||
async fetch(request) { | ||
const url = new URL(request.url); | ||
if (url.pathname !== "/test") { | ||
return new Response("ng: invalid path"); | ||
} | ||
const params = url.searchParams; | ||
const kemStr = params.get("kem"); | ||
const kdfStr = params.get("kdf"); | ||
const aeadStr = params.get("aead"); | ||
if (kemStr === null || kdfStr === null || aeadStr === null) { | ||
return new Response("ng: invalid params"); | ||
} | ||
const kem = Number.parseInt(kemStr); | ||
const kdf = Number.parseInt(kdfStr); | ||
const aead = Number.parseInt(aeadStr); | ||
if (Number.isNaN(kem) || Number.isNaN(kdf) || Number.isNaN(aead)) { | ||
return new Response("ng: invalid params"); | ||
} | ||
|
||
try { | ||
const suite = new hpke.CipherSuite({ kem: kem, kdf: kdf, aead: aead }); | ||
const rkp = await suite.generateKeyPair(); | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey, | ||
}); | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp, | ||
enc: sender.enc, | ||
}); | ||
const ct = await sender.seal(new TextEncoder().encode("hello world!")); | ||
const pt = await recipient.open(ct); | ||
if ("hello world!" !== new TextDecoder().decode(pt)) { | ||
return new Response("ng"); | ||
} | ||
} catch (e) { | ||
return new Response("ng: " + e.message); | ||
} | ||
return new Response("ok"); | ||
return await testServer(request); | ||
}, | ||
}; |
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,41 @@ | ||
import * as hpke from "./hpke.js"; | ||
|
||
export async function testServer(request) { | ||
const url = new URL(request.url); | ||
if (url.pathname !== "/test") { | ||
return new Response("ng: invalid path"); | ||
} | ||
const params = url.searchParams; | ||
const kemStr = params.get("kem"); | ||
const kdfStr = params.get("kdf"); | ||
const aeadStr = params.get("aead"); | ||
if (kemStr === null || kdfStr === null || aeadStr === null) { | ||
return new Response("ng: invalid params"); | ||
} | ||
const kem = Number.parseInt(kemStr); | ||
const kdf = Number.parseInt(kdfStr); | ||
const aead = Number.parseInt(aeadStr); | ||
if (Number.isNaN(kem) || Number.isNaN(kdf) || Number.isNaN(aead)) { | ||
return new Response("ng: invalid params"); | ||
} | ||
|
||
try { | ||
const suite = new hpke.CipherSuite({ kem: kem, kdf: kdf, aead: aead }); | ||
const rkp = await suite.generateKeyPair(); | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey, | ||
}); | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp, | ||
enc: sender.enc, | ||
}); | ||
const ct = await sender.seal(new TextEncoder().encode("hello world!")); | ||
const pt = await recipient.open(ct); | ||
if ("hello world!" !== new TextDecoder().decode(pt)) { | ||
return new Response("ng"); | ||
} | ||
} catch (e) { | ||
return new Response("ng: " + e.message); | ||
} | ||
return new Response("ok"); | ||
} |
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 |
---|---|---|
@@ -1,44 +1,8 @@ | ||
import * as hpke from "./hpke.js"; | ||
import * as secp256k1 from "./hpke-dhkemSecp256k1HkdfSha256.js"; | ||
import { testServer } from "../../server.js"; | ||
|
||
export default { | ||
port: 3001, | ||
async fetch(request) { | ||
const url = new URL(request.url); | ||
if (url.pathname !== "/test") { | ||
return new Response("ng: invalid path"); | ||
} | ||
const params = url.searchParams; | ||
const kdfStr = params.get("kdf"); | ||
const aeadStr = params.get("aead"); | ||
if (kdfStr === null || aeadStr === null) { | ||
return new Response("ng: invalid params"); | ||
} | ||
const kem = new secp256k1.DhkemSecp256k1HkdfSha256(); | ||
const kdf = Number.parseInt(kdfStr); | ||
const aead = Number.parseInt(aeadStr); | ||
if (Number.isNaN(kdf) || Number.isNaN(aead)) { | ||
return new Response("ng: invalid params"); | ||
} | ||
|
||
try { | ||
const suite = new hpke.CipherSuite({ kem: kem, kdf: kdf, aead: aead }); | ||
const rkp = await suite.generateKeyPair(); | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey, | ||
}); | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp, | ||
enc: sender.enc, | ||
}); | ||
const ct = await sender.seal(new TextEncoder().encode("hello world!")); | ||
const pt = await recipient.open(ct); | ||
if ("hello world!" !== new TextDecoder().decode(pt)) { | ||
return new Response("ng"); | ||
} | ||
} catch (e) { | ||
return new Response("ng: " + e.message); | ||
} | ||
return new Response("ok"); | ||
return await testServer(request); | ||
}, | ||
}; |
40 changes: 2 additions & 38 deletions
40
x/dhkemSecp256k1HkdfSha256/test/runtimes/cloudflare/src/index.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,7 @@ | ||
import * as hpke from "./hpke.js"; | ||
import * as secp256k1 from "./hpke-dhkemSecp256k1HkdfSha256.js"; | ||
import { testServer } from "../../server.js"; | ||
|
||
export default { | ||
async fetch(request) { | ||
const url = new URL(request.url); | ||
if (url.pathname !== "/test") { | ||
return new Response("ng: invalid path"); | ||
} | ||
const params = url.searchParams; | ||
const kdfStr = params.get("kdf"); | ||
const aeadStr = params.get("aead"); | ||
if (kdfStr === null || aeadStr === null) { | ||
return new Response("ng: params not found"); | ||
} | ||
const kem = new secp256k1.DhkemSecp256k1HkdfSha256(); | ||
const kdf = Number.parseInt(kdfStr); | ||
const aead = Number.parseInt(aeadStr); | ||
if (Number.isNaN(kdf) || Number.isNaN(aead)) { | ||
return new Response("ng: invalid int params"); | ||
} | ||
|
||
try { | ||
const suite = new hpke.CipherSuite({ kem: kem, kdf: kdf, aead: aead }); | ||
const rkp = await suite.generateKeyPair(); | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey, | ||
}); | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp, | ||
enc: sender.enc, | ||
}); | ||
const ct = await sender.seal(new TextEncoder().encode("hello world!")); | ||
const pt = await recipient.open(ct); | ||
if ("hello world!" !== new TextDecoder().decode(pt)) { | ||
return new Response("ng"); | ||
} | ||
} catch (e) { | ||
return new Response("ng: " + e.message); | ||
} | ||
return new Response("ok"); | ||
return await testServer(request); | ||
}, | ||
}; |
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,41 @@ | ||
import * as hpke from "./hpke.js"; | ||
import * as secp256k1 from "./hpke-dhkemSecp256k1HkdfSha256.js"; | ||
|
||
export async function testServer(request) { | ||
const url = new URL(request.url); | ||
if (url.pathname !== "/test") { | ||
return new Response("ng: invalid path"); | ||
} | ||
const params = url.searchParams; | ||
const kdfStr = params.get("kdf"); | ||
const aeadStr = params.get("aead"); | ||
if (kdfStr === null || aeadStr === null) { | ||
return new Response("ng: invalid params"); | ||
} | ||
const kem = new secp256k1.DhkemSecp256k1HkdfSha256(); | ||
const kdf = Number.parseInt(kdfStr); | ||
const aead = Number.parseInt(aeadStr); | ||
if (Number.isNaN(kdf) || Number.isNaN(aead)) { | ||
return new Response("ng: invalid params"); | ||
} | ||
|
||
try { | ||
const suite = new hpke.CipherSuite({ kem: kem, kdf: kdf, aead: aead }); | ||
const rkp = await suite.generateKeyPair(); | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey, | ||
}); | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp, | ||
enc: sender.enc, | ||
}); | ||
const ct = await sender.seal(new TextEncoder().encode("hello world!")); | ||
const pt = await recipient.open(ct); | ||
if ("hello world!" !== new TextDecoder().decode(pt)) { | ||
return new Response("ng"); | ||
} | ||
} catch (e) { | ||
return new Response("ng: " + e.message); | ||
} | ||
return new Response("ok"); | ||
} |