hpke 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -47,11 +47,17 @@ function getStringFromWasm0(ptr, len) {
47
47
  return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
48
48
  }
49
49
 
50
- function _assertClass(instance, klass) {
51
- if (!(instance instanceof klass)) {
52
- throw new Error(`expected instance of ${klass.name}`);
50
+ let cachedInt32Memory0 = new Int32Array();
51
+
52
+ function getInt32Memory0() {
53
+ if (cachedInt32Memory0.byteLength === 0) {
54
+ cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
53
55
  }
54
- return instance.ptr;
56
+ return cachedInt32Memory0;
57
+ }
58
+
59
+ function getArrayU8FromWasm0(ptr, len) {
60
+ return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
55
61
  }
56
62
 
57
63
  let WASM_VECTOR_LEN = 0;
@@ -63,68 +69,57 @@ function passArray8ToWasm0(arg, malloc) {
63
69
  return ptr;
64
70
  }
65
71
 
66
- let cachedInt32Memory0 = new Int32Array();
67
-
68
- function getInt32Memory0() {
69
- if (cachedInt32Memory0.byteLength === 0) {
70
- cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
72
+ function _assertClass(instance, klass) {
73
+ if (!(instance instanceof klass)) {
74
+ throw new Error(`expected instance of ${klass.name}`);
71
75
  }
72
- return cachedInt32Memory0;
73
- }
74
-
75
- function getArrayU8FromWasm0(ptr, len) {
76
- return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
76
+ return instance.ptr;
77
77
  }
78
78
  /**
79
79
  *
80
- *`base_mode_open` provides an interface to [`hpke::single_shot_open`]
81
- *that does not require compile time selection of an algorithm. Instead,
82
- *the selected algorithm is provided through the [`Config`] passed as
83
- *the first argument.
80
+ *`base_mode_seal` provides an interface to [`hpke::single_shot_seal`]
81
+ *that does not require compile time selection of an
82
+ *algorithm. Instead, the selected algorithm is provided through the
83
+ *[`Config`] passed as the first argument.
84
84
  *
85
- *Requires the `base-mode-open` crate feature to be enabled.
85
+ *Requires the `base-mode-seal` crate feature to be enabled.
86
86
  *
87
87
  *# Errors
88
88
  *
89
89
  *This will return an `Result::Err` variant if:
90
90
  *
91
- ** we are unable to deserialize the private key or encapsulated key
92
- ** there is an error in key decapsulation
93
- ** there is an error in decryption
91
+ ** we are unable to deserialize the recipient public key
92
+ ** there is an error in key encapsultion
93
+ ** there is an error in encryption
94
+ *
94
95
  *
95
96
  * @param {Config} config
96
- * @param {Uint8Array} private_key
97
- * @param {Uint8Array} encapped_key
97
+ * @param {Uint8Array} recipient_public_key
98
98
  * @param {Uint8Array} info
99
- * @param {Uint8Array} ciphertext
99
+ * @param {Uint8Array} plaintext
100
100
  * @param {Uint8Array} aad
101
- * @returns {Uint8Array}
101
+ * @returns {EncappedKeyAndCiphertext}
102
102
  */
103
- export function base_mode_open(config, private_key, encapped_key, info, ciphertext, aad) {
103
+ export function base_mode_seal(config, recipient_public_key, info, plaintext, aad) {
104
104
  try {
105
105
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
106
106
  _assertClass(config, Config);
107
- const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
107
+ const ptr0 = passArray8ToWasm0(recipient_public_key, wasm.__wbindgen_malloc);
108
108
  const len0 = WASM_VECTOR_LEN;
109
- const ptr1 = passArray8ToWasm0(encapped_key, wasm.__wbindgen_malloc);
109
+ const ptr1 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
110
110
  const len1 = WASM_VECTOR_LEN;
111
- const ptr2 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
111
+ const ptr2 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
112
112
  const len2 = WASM_VECTOR_LEN;
113
- const ptr3 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
113
+ const ptr3 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
114
114
  const len3 = WASM_VECTOR_LEN;
115
- const ptr4 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
116
- const len4 = WASM_VECTOR_LEN;
117
- wasm.base_mode_open(retptr, config.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
115
+ wasm.base_mode_seal(retptr, config.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
118
116
  var r0 = getInt32Memory0()[retptr / 4 + 0];
119
117
  var r1 = getInt32Memory0()[retptr / 4 + 1];
120
118
  var r2 = getInt32Memory0()[retptr / 4 + 2];
121
- var r3 = getInt32Memory0()[retptr / 4 + 3];
122
- if (r3) {
123
- throw takeObject(r2);
119
+ if (r2) {
120
+ throw takeObject(r1);
124
121
  }
125
- var v5 = getArrayU8FromWasm0(r0, r1).slice();
126
- wasm.__wbindgen_free(r0, r1 * 1);
127
- return v5;
122
+ return EncappedKeyAndCiphertext.__wrap(r0);
128
123
  } finally {
129
124
  wasm.__wbindgen_add_to_stack_pointer(16);
130
125
  }
@@ -132,49 +127,54 @@ export function base_mode_open(config, private_key, encapped_key, info, cipherte
132
127
 
133
128
  /**
134
129
  *
135
- *`base_mode_seal` provides an interface to [`hpke::single_shot_seal`]
136
- *that does not require compile time selection of an
137
- *algorithm. Instead, the selected algorithm is provided through the
138
- *[`Config`] passed as the first argument.
130
+ *`base_mode_open` provides an interface to [`hpke::single_shot_open`]
131
+ *that does not require compile time selection of an algorithm. Instead,
132
+ *the selected algorithm is provided through the [`Config`] passed as
133
+ *the first argument.
139
134
  *
140
- *Requires the `base-mode-seal` crate feature to be enabled.
135
+ *Requires the `base-mode-open` crate feature to be enabled.
141
136
  *
142
137
  *# Errors
143
138
  *
144
139
  *This will return an `Result::Err` variant if:
145
140
  *
146
- ** we are unable to deserialize the recipient public key
147
- ** there is an error in key encapsultion
148
- ** there is an error in encryption
149
- *
141
+ ** we are unable to deserialize the private key or encapsulated key
142
+ ** there is an error in key decapsulation
143
+ ** there is an error in decryption
150
144
  *
151
145
  * @param {Config} config
152
- * @param {Uint8Array} recipient_public_key
146
+ * @param {Uint8Array} private_key
147
+ * @param {Uint8Array} encapped_key
153
148
  * @param {Uint8Array} info
154
- * @param {Uint8Array} plaintext
149
+ * @param {Uint8Array} ciphertext
155
150
  * @param {Uint8Array} aad
156
- * @returns {EncappedKeyAndCiphertext}
151
+ * @returns {Uint8Array}
157
152
  */
158
- export function base_mode_seal(config, recipient_public_key, info, plaintext, aad) {
153
+ export function base_mode_open(config, private_key, encapped_key, info, ciphertext, aad) {
159
154
  try {
160
155
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
161
156
  _assertClass(config, Config);
162
- const ptr0 = passArray8ToWasm0(recipient_public_key, wasm.__wbindgen_malloc);
157
+ const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
163
158
  const len0 = WASM_VECTOR_LEN;
164
- const ptr1 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
159
+ const ptr1 = passArray8ToWasm0(encapped_key, wasm.__wbindgen_malloc);
165
160
  const len1 = WASM_VECTOR_LEN;
166
- const ptr2 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
161
+ const ptr2 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
167
162
  const len2 = WASM_VECTOR_LEN;
168
- const ptr3 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
163
+ const ptr3 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
169
164
  const len3 = WASM_VECTOR_LEN;
170
- wasm.base_mode_seal(retptr, config.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
165
+ const ptr4 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
166
+ const len4 = WASM_VECTOR_LEN;
167
+ wasm.base_mode_open(retptr, config.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
171
168
  var r0 = getInt32Memory0()[retptr / 4 + 0];
172
169
  var r1 = getInt32Memory0()[retptr / 4 + 1];
173
170
  var r2 = getInt32Memory0()[retptr / 4 + 2];
174
- if (r2) {
175
- throw takeObject(r1);
171
+ var r3 = getInt32Memory0()[retptr / 4 + 3];
172
+ if (r3) {
173
+ throw takeObject(r2);
176
174
  }
177
- return EncappedKeyAndCiphertext.__wrap(r0);
175
+ var v5 = getArrayU8FromWasm0(r0, r1).slice();
176
+ wasm.__wbindgen_free(r0, r1 * 1);
177
+ return v5;
178
178
  } finally {
179
179
  wasm.__wbindgen_add_to_stack_pointer(16);
180
180
  }
@@ -189,24 +189,6 @@ function handleError(f, args) {
189
189
  }
190
190
  /**
191
191
  *
192
- *Kdf represents an key derivation function, as per
193
- *[RFC9180§7.2](https://www.rfc-editor.org/rfc/rfc9180.html#section-7.2)
194
- */
195
- export const Kdf = Object.freeze({
196
- /**
197
- * Sha256 [RFC5869](https://www.rfc-editor.org/info/rfc5869)
198
- */
199
- Sha256:1,"1":"Sha256",
200
- /**
201
- * Sha384 [RFC5869](https://www.rfc-editor.org/info/rfc5869)
202
- */
203
- Sha384:2,"2":"Sha384",
204
- /**
205
- * Sha512 [RFC5869](https://www.rfc-editor.org/info/rfc5869)
206
- */
207
- Sha512:3,"3":"Sha512", });
208
- /**
209
- *
210
192
  *Aead represents an authenticated encryption with additional data
211
193
  *encryption function, as per [RFC9180§7.3](https://www.rfc-editor.org/rfc/rfc9180.html#section-7.3)
212
194
  */
@@ -225,6 +207,24 @@ AesGcm256:2,"2":"AesGcm256",
225
207
  ChaCha20Poly1305:3,"3":"ChaCha20Poly1305", });
226
208
  /**
227
209
  *
210
+ *Kdf represents an key derivation function, as per
211
+ *[RFC9180§7.2](https://www.rfc-editor.org/rfc/rfc9180.html#section-7.2)
212
+ */
213
+ export const Kdf = Object.freeze({
214
+ /**
215
+ * Sha256 [RFC5869](https://www.rfc-editor.org/info/rfc5869)
216
+ */
217
+ Sha256:1,"1":"Sha256",
218
+ /**
219
+ * Sha384 [RFC5869](https://www.rfc-editor.org/info/rfc5869)
220
+ */
221
+ Sha384:2,"2":"Sha384",
222
+ /**
223
+ * Sha512 [RFC5869](https://www.rfc-editor.org/info/rfc5869)
224
+ */
225
+ Sha512:3,"3":"Sha512", });
226
+ /**
227
+ *
228
228
  *Kem represents an asymmetric key encapsulation mechanism, as per
229
229
  *[RFC9180§7.1][section-7.1]. Currently only two of options listed in
230
230
  *the hpke draft are available.
@@ -683,23 +683,14 @@ async function load(module, imports) {
683
683
  function getImports() {
684
684
  const imports = {};
685
685
  imports.wbg = {};
686
- imports.wbg.__wbg_hpkeerror_new = function(arg0) {
687
- const ret = HpkeError.__wrap(arg0);
688
- return addHeapObject(ret);
689
- };
690
686
  imports.wbg.__wbg_idlookuperror_new = function(arg0) {
691
687
  const ret = IdLookupError.__wrap(arg0);
692
688
  return addHeapObject(ret);
693
689
  };
694
- imports.wbg.__wbg_randomFillSync_065afffde01daa66 = function() { return handleError(function (arg0, arg1, arg2) {
695
- getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2));
696
- }, arguments) };
697
- imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
698
- takeObject(arg0);
690
+ imports.wbg.__wbg_hpkeerror_new = function(arg0) {
691
+ const ret = HpkeError.__wrap(arg0);
692
+ return addHeapObject(ret);
699
693
  };
700
- imports.wbg.__wbg_getRandomValues_b99eec4244a475bb = function() { return handleError(function (arg0, arg1) {
701
- getObject(arg0).getRandomValues(getObject(arg1));
702
- }, arguments) };
703
694
  imports.wbg.__wbg_process_0cc2ada8524d6f83 = function(arg0) {
704
695
  const ret = getObject(arg0).process;
705
696
  return addHeapObject(ret);
@@ -721,6 +712,9 @@ function getImports() {
721
712
  const ret = typeof(getObject(arg0)) === 'string';
722
713
  return ret;
723
714
  };
715
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
716
+ takeObject(arg0);
717
+ };
724
718
  imports.wbg.__wbg_crypto_2036bed7c44c25e7 = function(arg0) {
725
719
  const ret = getObject(arg0).crypto;
726
720
  return addHeapObject(ret);
@@ -737,6 +731,12 @@ function getImports() {
737
731
  const ret = getObject(arg0).require(getStringFromWasm0(arg1, arg2));
738
732
  return addHeapObject(ret);
739
733
  }, arguments) };
734
+ imports.wbg.__wbg_getRandomValues_b99eec4244a475bb = function() { return handleError(function (arg0, arg1) {
735
+ getObject(arg0).getRandomValues(getObject(arg1));
736
+ }, arguments) };
737
+ imports.wbg.__wbg_randomFillSync_065afffde01daa66 = function() { return handleError(function (arg0, arg1, arg2) {
738
+ getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2));
739
+ }, arguments) };
740
740
  imports.wbg.__wbg_newnoargs_b5b063fc6c2f0376 = function(arg0, arg1) {
741
741
  const ret = new Function(getStringFromWasm0(arg0, arg1));
742
742
  return addHeapObject(ret);
Binary file
@@ -1,24 +1,12 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
- export function base_mode_open(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number): void;
5
- export function __wbg_config_free(a: number): void;
6
- export function __wbg_get_config_aead(a: number): number;
7
- export function __wbg_set_config_aead(a: number, b: number): void;
8
- export function __wbg_get_config_kdf(a: number): number;
9
- export function __wbg_set_config_kdf(a: number, b: number): void;
10
- export function __wbg_get_config_kem(a: number): number;
11
- export function __wbg_set_config_kem(a: number, b: number): void;
12
- export function config_base_mode_seal(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void;
13
- export function config_base_mode_open(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number): void;
14
- export function config_try_from_ids(a: number, b: number, c: number, d: number): void;
15
4
  export function __wbg_keypair_free(a: number): void;
16
5
  export function __wbg_get_keypair_public_key(a: number, b: number): void;
17
6
  export function __wbg_set_keypair_public_key(a: number, b: number, c: number): void;
18
7
  export function __wbg_get_keypair_private_key(a: number, b: number): void;
19
8
  export function __wbg_set_keypair_private_key(a: number, b: number, c: number): void;
20
9
  export function keypair_new(a: number): number;
21
- export function base_mode_seal(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void;
22
10
  export function __wbg_encappedkeyandciphertext_free(a: number): void;
23
11
  export function __wbg_get_encappedkeyandciphertext_encapped_key(a: number, b: number): void;
24
12
  export function __wbg_set_encappedkeyandciphertext_encapped_key(a: number, b: number, c: number): void;
@@ -26,7 +14,19 @@ export function __wbg_get_encappedkeyandciphertext_ciphertext(a: number, b: numb
26
14
  export function __wbg_set_encappedkeyandciphertext_ciphertext(a: number, b: number, c: number): void;
27
15
  export function __wbg_idlookuperror_free(a: number): void;
28
16
  export function __wbg_hpkeerror_free(a: number): void;
17
+ export function base_mode_seal(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void;
18
+ export function base_mode_open(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number): void;
19
+ export function __wbg_config_free(a: number): void;
20
+ export function __wbg_get_config_aead(a: number): number;
21
+ export function __wbg_set_config_aead(a: number, b: number): void;
22
+ export function __wbg_get_config_kdf(a: number): number;
23
+ export function __wbg_set_config_kdf(a: number, b: number): void;
24
+ export function __wbg_get_config_kem(a: number): number;
25
+ export function __wbg_set_config_kem(a: number, b: number): void;
26
+ export function config_base_mode_seal(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void;
27
+ export function config_base_mode_open(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number): void;
28
+ export function config_try_from_ids(a: number, b: number, c: number, d: number): void;
29
29
  export function __wbindgen_add_to_stack_pointer(a: number): number;
30
- export function __wbindgen_malloc(a: number): number;
31
30
  export function __wbindgen_free(a: number, b: number): void;
31
+ export function __wbindgen_malloc(a: number): number;
32
32
  export function __wbindgen_exn_store(a: number): void;