Skip to content

Commit db9685e

Browse files
committed
ver 0.2.8
1 parent 7f6899b commit db9685e

File tree

8 files changed

+220
-116
lines changed

8 files changed

+220
-116
lines changed

deno.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tls/enum",
3-
"version": "0.2.7",
3+
"version": "0.2.8",
44
"exports": "./src/mod.ts",
55
"publish": {
66
"exclude": ["dist/"]
@@ -13,9 +13,10 @@
1313
}
1414
},
1515
"imports": {
16-
"@noble/curves": "npm:@noble/curves@^1.6.0",
16+
"@noble/curves": "npm:@noble/curves@^1.7.0",
1717
"@std/assert": "jsr:@std/assert@^1.0.2",
1818
"@tls/extension": "jsr:@tls/extension@^0.2.0",
19+
"@tls/record": "jsr:@tls/record@^0.0.6",
1920
"@tls/struct": "jsr:@tls/struct@^0.2.6"
2021
}
2122
}

src/contentype.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// deno-lint-ignore-file no-slow-types
22
// @ts-self-types="../type/contentype.d.ts"
33

4-
import { Uint8 } from "./dep.ts";
4+
import { Uint8, TLSPlaintext } from "./dep.ts";
55
import { Enum } from "./enum.js";
6-
6+
import { Version } from "./version.js";
77

88
/**
99
* The higher-level protocol used to process the enclosed
@@ -35,6 +35,14 @@ export class ContentType extends Enum {
3535

3636
/**return 8 */
3737
get bit() { return 8 }
38+
39+
tlsPlainText(fragment){
40+
return TLSPlaintext.createFrom(
41+
this,
42+
Version.TLS13,
43+
fragment
44+
)
45+
}
3846
}
3947

4048
//npx -p typescript tsc ./src/contentype.js --declaration --allowJs --emitDeclarationOnly --lib ESNext --outDir ./dist

src/dep.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
export { Struct, Constrained, Byte } from "@tls/struct"
22
export { Uint8, Uint16, Uint24, Uint32 } from "@tls/struct"
33
export { Extension, KeyExchange, KeyShareEntry } from "@tls/extension"
4-
export { p256 } from 'npm:@noble/[email protected]/p256'
5-
export { p384 } from 'npm:@noble/[email protected]/p384'
6-
export { p521 } from 'npm:@noble/[email protected]/p521'
7-
export { x25519 } from 'npm:@noble/[email protected]/ed25519'
8-
export { x448 } from 'npm:@noble/[email protected]/ed448'
4+
export { p256 } from '@noble/curves/p256'
5+
export { p384 } from '@noble/curves/p384'
6+
export { p521 } from '@noble/curves/p521'
7+
export { x25519 } from '@noble/curves/ed25519'
8+
export { x448 } from '@noble/curves/ed448'
9+
export * as utils from "@noble/curves/abstract/utils"
10+
export { TLSPlaintext } from "@tls/record"
11+

src/handshaketype.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,15 @@ export class HandshakeType extends Enum {
103103
handshake(message){
104104
return Handshake.fromMessage(this, message)
105105
}
106+
107+
get Uint8(){ return Uint8.fromValue(+this)}
106108
}
107109

108-
export class Handshake extends Struct {
110+
export class Handshake extends Uint8Array {
109111
msg_type
110112
message
111113
static fromMessage(msg_type, message){
112-
return new Handshake(msg_type, Uint24.fromValue(message.length), message)
114+
return new Handshake(msg_type, message)
113115
}
114116
static from(array){
115117
const copy = Uint8Array.from(array)
@@ -118,10 +120,12 @@ export class Handshake extends Struct {
118120
const message = copy.subarray(4, 4 + lengthOf)
119121
return new Handshake(msg_type, lengthOf, message)
120122
}
121-
constructor(msg_type, length, message){
122-
super(+msg_type, length, message)
123+
constructor(msg_type, message){
124+
const struct = new Struct(msg_type.Uint8, Uint24.fromValue(message.length), message)
125+
super(struct)
123126
this.msg_type = msg_type;
124127
this.message = message
128+
this.items = struct.items
125129
}
126130
}
127131

test/enum_test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Enum } from "../src/enum.js";
22
import { assertEquals } from "jsr:@std/assert";
3+
34
/**
45
* @class Color
56
* @extends Enum
@@ -65,3 +66,4 @@ Deno.test(
6566
assertEquals(Color.GREEN.name, "GREEN")
6667
}
6768
)
69+

test/namedgroup_test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,15 @@ Deno.test(
1919
}
2020
)
2121

22-
const x25519 = NamedGroup.X25519.keyShareEntry(); debugger;
22+
//const x25519 = NamedGroup.X25519.keyShareEntry();
23+
24+
const x25519 = NamedGroup.X25519;
25+
assertEquals(x25519.name, 'X25519')
26+
const pub = x25519.keyGen.getPublicKey(x25519.privateKey);
27+
assertEquals(pub.length, 32)
28+
const peerPublicKey = crypto.getRandomValues(new Uint8Array(32));
29+
assertEquals(peerPublicKey.length, 32)
30+
const sharedKey = x25519.getSharedKey(peerPublicKey)
31+
assertEquals(sharedKey.length, 32)
32+
33+
debugger;

type/contentype.d.ts

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,57 @@
1+
import { Uint8, TLSPlaintext } from "../src/dep.ts";
2+
import { Enum } from "../src/enum.js";
3+
import { Version } from "../src/version.js";
4+
15
/**
2-
* The higher-level protocol used to process the enclosed
3-
fragment
6+
* Represents the higher-level protocol used to process the enclosed fragment.
7+
* Defined in RFC 8446 Section 5.1.
48
* @see https://datatracker.ietf.org/doc/html/rfc8446#section-5.1
5-
* @export
6-
* @extends {Enum}
79
*/
810
export class ContentType extends Enum {
9-
static INVALID: ContentType;
10-
static CHANGE_CIPHER_SPEC: ContentType;
11-
static ALERT: ContentType;
12-
static HANDSHAKE: ContentType;
13-
static APPLICATION_DATA: ContentType;
14-
/**
15-
* check octet and return valid ContentType
16-
*
17-
* @static
18-
* @param {Uint8Array} octet
19-
* @returns {ContentType }
20-
*/
21-
static from(octet: Uint8Array): ContentType;
22-
/**return 8 */
23-
get bit(): number;
24-
25-
/**return Uint8 */
26-
get Uint8(): Uint8
11+
/** Represents an invalid ContentType (value 0). */
12+
static INVALID: ContentType;
13+
14+
/** Represents the ChangeCipherSpec ContentType (value 20). */
15+
static CHANGE_CIPHER_SPEC: ContentType;
16+
17+
/** Represents the Alert ContentType (value 21). */
18+
static ALERT: ContentType;
19+
20+
/** Represents the Handshake ContentType (value 22). */
21+
static HANDSHAKE: ContentType;
22+
23+
/** Represents the ApplicationData ContentType (value 23). */
24+
static APPLICATION_DATA: ContentType;
25+
26+
/**
27+
* Checks the given octet and returns a valid ContentType instance.
28+
*
29+
* @param {Uint8Array} octet - A single-octet Uint8Array to evaluate.
30+
* @returns {ContentType} The corresponding ContentType or throws an error if invalid.
31+
*/
32+
static from(octet: Uint8Array): ContentType;
33+
34+
/**
35+
* Returns the Uint8 representation of the ContentType.
36+
*
37+
* @readonly
38+
* @type {Uint8}
39+
*/
40+
get Uint8(): Uint8;
41+
42+
/**
43+
* Returns the bit size of the ContentType.
44+
*
45+
* @readonly
46+
* @type {8}
47+
*/
48+
get bit(): 8;
49+
50+
/**
51+
* Creates a `TLSPlaintext` instance using the ContentType, TLS version, and fragment.
52+
*
53+
* @param {Uint8Array} fragment - The plaintext fragment to include.
54+
* @returns {TLSPlaintext} A TLSPlaintext object created with the specified parameters.
55+
*/
56+
tlsPlainText(fragment: Uint8Array): TLSPlaintext;
2757
}
28-
import { Uint8 } from "../src/dep.ts";
29-
import { Enum } from "../src/enum.js";

0 commit comments

Comments
 (0)