Skip to content

Commit

Permalink
Regenerated ffi bindings (#47)
Browse files Browse the repository at this point in the history
* Regenerated ffi bindings

* Fix lints
  • Loading branch information
jonasfj authored Oct 18, 2022
1 parent ae7fb13 commit 558bbab
Show file tree
Hide file tree
Showing 36 changed files with 421 additions and 840 deletions.
4 changes: 2 additions & 2 deletions lib/src/boringssl/bindings/ffigen.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: WebCrypto
description: 'Bindings to src/webcrypto.h.'
output: 'lib/src/boringssl/bindings/generated_bindings.dart'
output: generated_bindings.dart
headers:
entry-points:
- src/webcrypto.h
- ../../../../src/webcrypto.h
comments:
style: any
length: full
Expand Down
2 changes: 2 additions & 0 deletions lib/src/boringssl/lookup/symbols.generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: constant_identifier_names

/// **GENERATED FILE DO NOT MODIFY**
///
/// This file is generated from `src/symbols.yaml` using:
Expand Down
4 changes: 2 additions & 2 deletions lib/src/impl_ffi/impl_ffi.aes_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Uint8List _aesImportRawKey(List<int> keyData) {
throw UnsupportedError('192-bit AES keys are not supported');
}
if (keyData.length != 16 && keyData.length != 32) {
throw FormatException('keyData for AES must be 128 or 256 bits');
throw const FormatException('keyData for AES must be 128 or 256 bits');
}
return Uint8List.fromList(keyData);
}
Expand Down Expand Up @@ -86,7 +86,7 @@ Uint8List _aesGenerateKey(int length) {
throw UnsupportedError('192-bit AES keys are not supported');
}
if (length != 128 && length != 256) {
throw FormatException('keyData for AES must be 128 or 256 bits');
throw const FormatException('keyData for AES must be 128 or 256 bits');
}
final keyData = Uint8List(length ~/ 8);
fillRandomBytes(keyData);
Expand Down
2 changes: 2 additions & 0 deletions lib/src/impl_ffi/impl_ffi.aescbc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

part of impl_ffi;

Future<AesCbcSecretKey> aesCbc_importRawKey(List<int> keyData) async =>
Expand Down
8 changes: 6 additions & 2 deletions lib/src/impl_ffi/impl_ffi.aesctr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

part of impl_ffi;

Future<AesCtrSecretKey> aesCtr_importRawKey(List<int> keyData) async =>
Expand Down Expand Up @@ -66,7 +68,7 @@ Stream<Uint8List> _aesCtrEncryptOrDecrypt(
assert(key.length == 16 || key.length == 32);
final cipher =
key.length == 16 ? ssl.EVP_aes_128_ctr() : ssl.EVP_aes_256_ctr();
final blockSize = AES_BLOCK_SIZE;
const blockSize = AES_BLOCK_SIZE;

// Find the number of possible counter values, as the counter may not be
// reused this will limit how much data we can process. If we get more data
Expand Down Expand Up @@ -129,7 +131,9 @@ Stream<Uint8List> _aesCtrEncryptOrDecrypt(
M = data.length - offset;
// Do not consume more bytes than allowed after wrap-around
if (bytes_after_wraparound.toInt() < M) {
throw FormatException('input is too large for the counter length');
throw const FormatException(
'input is too large for the counter length',
);
}
bytes_after_wraparound -= BigInt.from(M);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/src/impl_ffi/impl_ffi.aesgcm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

part of impl_ffi;

Future<AesGcmSecretKey> aesGcm_importRawKey(List<int> keyData) async =>
Expand Down
1 change: 1 addition & 0 deletions lib/src/impl_ffi/impl_ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

library impl_ffi;

import 'dart:async';
Expand Down
4 changes: 2 additions & 2 deletions lib/src/impl_ffi/impl_ffi.digest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class _Hash implements Hash {
ffi.Pointer<EVP_MD> Function() get _algorithm;

/// Get an instantiated [EVP_MD] for this hash algorithm.
ffi.Pointer<EVP_MD> get MD {
ffi.Pointer<EVP_MD> get _md {
final md = _algorithm();
_checkOp(md.address != 0, fallback: 'failed to instantiate hash algorithm');
return md;
Expand All @@ -52,7 +52,7 @@ abstract class _Hash implements Hash {
ArgumentError.checkNotNull(data, 'data');

return await _withEVP_MD_CTX((ctx) async {
_checkOp(ssl.EVP_DigestInit(ctx, MD) == 1);
_checkOp(ssl.EVP_DigestInit(ctx, _md) == 1);
await _streamToUpdate(data, ctx, ssl.EVP_DigestUpdate);
final size = ssl.EVP_MD_CTX_size(ctx);
_checkOp(size > 0);
Expand Down
2 changes: 2 additions & 0 deletions lib/src/impl_ffi/impl_ffi.ecdh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

part of impl_ffi;

Future<EcdhPrivateKey> ecdhPrivateKey_importPkcs8Key(
Expand Down
10 changes: 6 additions & 4 deletions lib/src/impl_ffi/impl_ffi.ecdsa.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

part of impl_ffi;

/// Get valid value for `jwk.alg` property given an [EllipticCurve] for ECDSA.
Expand Down Expand Up @@ -208,13 +210,13 @@ class _EcdsaPrivateKey implements EcdsaPrivateKey {
Future<Uint8List> signStream(Stream<List<int>> data, Hash hash) async {
ArgumentError.checkNotNull(data, 'data');
ArgumentError.checkNotNull(hash, 'hash');
final _hash = _Hash.fromHash(hash).MD;
final md = _Hash.fromHash(hash)._md;

final sig = await _withEVP_MD_CTX((ctx) async {
_checkOpIsOne(ssl.EVP_DigestSignInit.invoke(
ctx,
ffi.nullptr,
_hash,
md,
ffi.nullptr,
_key,
));
Expand Down Expand Up @@ -266,7 +268,7 @@ class _EcdsaPublicKey implements EcdsaPublicKey {
ArgumentError.checkNotNull(signature, 'signature');
ArgumentError.checkNotNull(data, 'data');
ArgumentError.checkNotNull(hash, 'hash');
final _hash = _Hash.fromHash(hash).MD;
final md = _Hash.fromHash(hash)._md;

// Convert to DER signature
final sig = _convertEcdsaWebCryptoSignatureToDerSignature(_key, signature);
Expand All @@ -280,7 +282,7 @@ class _EcdsaPublicKey implements EcdsaPublicKey {
_checkOpIsOne(ssl.EVP_DigestVerifyInit.invoke(
ctx,
pctx,
_hash,
md,
ffi.nullptr,
_key,
));
Expand Down
4 changes: 3 additions & 1 deletion lib/src/impl_ffi/impl_ffi.hkdf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

part of impl_ffi;

Future<HkdfSecretKey> hkdfSecretKey_importRawKey(List<int> keyData) async {
Expand All @@ -38,7 +40,7 @@ class _HkdfSecretKey implements HkdfSecretKey {
if (length < 0) {
throw ArgumentError.value(length, 'length', 'must be positive integer');
}
final md = _Hash.fromHash(hash).MD;
final md = _Hash.fromHash(hash)._md;

// Mirroring limitations in chromium:
// https://chromium.googlesource.com/chromium/src/+/43d62c50b705f88c67b14539e91fd8fd017f70c4/components/webcrypto/algorithms/hkdf.cc#74
Expand Down
6 changes: 4 additions & 2 deletions lib/src/impl_ffi/impl_ffi.hmac.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

part of impl_ffi;

/// Convert [data] to [Uint8List] and zero to [lengthInBits] if given.
Expand Down Expand Up @@ -90,7 +92,7 @@ Future<HmacSecretKey> hmacSecretKey_importJsonWebKey(
Future<HmacSecretKey> hmacSecretKey_generateKey(Hash hash,
{int? length}) async {
final h = _Hash.fromHash(hash);
length ??= ssl.EVP_MD_size(h.MD) * 8;
length ??= ssl.EVP_MD_size(h._md) * 8;
final keyData = Uint8List((length / 8).ceil());
fillRandomBytes(keyData);

Expand Down Expand Up @@ -120,7 +122,7 @@ class _HmacSecretKey implements HmacSecretKey {
try {
_withDataAsPointer(_keyData, (ffi.Pointer<ffi.Void> p) {
final n = _keyData.length;
_checkOp(ssl.HMAC_Init_ex(ctx, p, n, _hash.MD, ffi.nullptr) == 1);
_checkOp(ssl.HMAC_Init_ex(ctx, p, n, _hash._md, ffi.nullptr) == 1);
});
await _streamToUpdate(data, ctx, ssl.HMAC_Update);

Expand Down
4 changes: 3 additions & 1 deletion lib/src/impl_ffi/impl_ffi.pbkdf2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

part of impl_ffi;

Future<Pbkdf2SecretKey> pbkdf2SecretKey_importRawKey(List<int> keyData) async {
Expand All @@ -38,7 +40,7 @@ class _Pbkdf2SecretKey implements Pbkdf2SecretKey {
if (length < 0) {
throw ArgumentError.value(length, 'length', 'must be positive integer');
}
final md = _Hash.fromHash(hash).MD;
final md = _Hash.fromHash(hash)._md;

// Mirroring limitations in chromium:
// https://chromium.googlesource.com/chromium/src/+/43d62c50b705f88c67b14539e91fd8fd017f70c4/components/webcrypto/algorithms/pbkdf2.cc#75
Expand Down
6 changes: 4 additions & 2 deletions lib/src/impl_ffi/impl_ffi.rsaoaep.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

part of impl_ffi;

String _rsaOaepJwkAlgFromHash(_Hash hash) {
Expand Down Expand Up @@ -185,7 +187,7 @@ class _RsaOaepPrivateKey implements RsaOaepPrivateKey {
Future<Uint8List> decryptBytes(List<int> data, {List<int>? label}) async {
return _rsaOaepeEncryptOrDecryptBytes(
_key,
_hash.MD,
_hash._md,
ssl.EVP_PKEY_decrypt_init,
ssl.EVP_PKEY_decrypt,
data,
Expand Down Expand Up @@ -220,7 +222,7 @@ class _RsaOaepPublicKey implements RsaOaepPublicKey {
Future<Uint8List> encryptBytes(List<int> data, {List<int>? label}) async {
return _rsaOaepeEncryptOrDecryptBytes(
_key,
_hash.MD,
_hash._md,
ssl.EVP_PKEY_encrypt_init,
ssl.EVP_PKEY_encrypt,
data,
Expand Down
13 changes: 9 additions & 4 deletions lib/src/impl_ffi/impl_ffi.rsapss.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

part of impl_ffi;

String _rsaPssJwkAlgFromHash(_Hash hash) {
Expand Down Expand Up @@ -125,7 +127,8 @@ class _RsaPssPrivateKey implements RsaPssPrivateKey {
return _withEVP_MD_CTX((ctx) async {
return await _withPEVP_PKEY_CTX((pctx) async {
_checkOpIsOne(
ssl.EVP_DigestSignInit.invoke(ctx, pctx, _hash.MD, ffi.nullptr, _key),
ssl.EVP_DigestSignInit.invoke(
ctx, pctx, _hash._md, ffi.nullptr, _key),
);
_checkOpIsOne(ssl.EVP_PKEY_CTX_set_rsa_padding(
pctx.value,
Expand All @@ -135,7 +138,8 @@ class _RsaPssPrivateKey implements RsaPssPrivateKey {
pctx.value,
saltLength,
));
_checkDataIsOne(ssl.EVP_PKEY_CTX_set_rsa_mgf1_md(pctx.value, _hash.MD));
_checkDataIsOne(
ssl.EVP_PKEY_CTX_set_rsa_mgf1_md(pctx.value, _hash._md));
await _streamToUpdate(data, ctx, ssl.EVP_DigestSignUpdate);
return _withAllocation(_sslAlloc<ffi.Size>(),
(ffi.Pointer<ffi.Size> len) {
Expand Down Expand Up @@ -206,7 +210,7 @@ class _RsaPssPublicKey implements RsaPssPublicKey {
_checkOpIsOne(ssl.EVP_DigestVerifyInit.invoke(
ctx,
pctx,
_hash.MD,
_hash._md,
ffi.nullptr,
_key,
));
Expand All @@ -218,7 +222,8 @@ class _RsaPssPublicKey implements RsaPssPublicKey {
pctx.value,
saltLength,
));
_checkDataIsOne(ssl.EVP_PKEY_CTX_set_rsa_mgf1_md(pctx.value, _hash.MD));
_checkDataIsOne(
ssl.EVP_PKEY_CTX_set_rsa_mgf1_md(pctx.value, _hash._md));
await _streamToUpdate(data, ctx, ssl.EVP_DigestVerifyUpdate);
return _withDataAsPointer(signature, (ffi.Pointer<ffi.Uint8> p) {
final result = ssl.EVP_DigestVerifyFinal(ctx, p, signature.length);
Expand Down
7 changes: 5 additions & 2 deletions lib/src/impl_ffi/impl_ffi.rsassapkcs1v15.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

part of impl_ffi;

String _rsassaPkcs1V15JwkAlgFromHash(_Hash hash) {
Expand Down Expand Up @@ -117,7 +119,8 @@ class _RsassaPkcs1V15PrivateKey implements RsassaPkcs1V15PrivateKey {
return _withEVP_MD_CTX((ctx) async {
return await _withPEVP_PKEY_CTX((pctx) async {
_checkOpIsOne(
ssl.EVP_DigestSignInit.invoke(ctx, pctx, _hash.MD, ffi.nullptr, _key),
ssl.EVP_DigestSignInit.invoke(
ctx, pctx, _hash._md, ffi.nullptr, _key),
);
_checkOpIsOne(
ssl.EVP_PKEY_CTX_set_rsa_padding(pctx.value, RSA_PKCS1_PADDING),
Expand Down Expand Up @@ -175,7 +178,7 @@ class _RsassaPkcs1V15PublicKey implements RsassaPkcs1V15PublicKey {
_checkOpIsOne(ssl.EVP_DigestVerifyInit.invoke(
ctx,
pctx,
_hash.MD,
_hash._md,
ffi.nullptr,
_key,
));
Expand Down
2 changes: 2 additions & 0 deletions lib/src/impl_ffi/impl_ffi.utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

part of impl_ffi;

/// Wrapper around [EVP_PKEY] which attaches finalizer and ensure that the
Expand Down
2 changes: 2 additions & 0 deletions lib/src/impl_js/impl_js.aescbc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

part of impl_js;

final _aesCbcAlgorithm = subtle.Algorithm(name: 'AES-CBC');
Expand Down
2 changes: 2 additions & 0 deletions lib/src/impl_js/impl_js.aesctr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

part of impl_js;

final _aesCtrAlgorithm = subtle.Algorithm(name: 'AES-CTR');
Expand Down
2 changes: 2 additions & 0 deletions lib/src/impl_js/impl_js.aesgcm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

part of impl_js;

final _aesGcmAlgorithm = subtle.Algorithm(name: 'AES-GCM');
Expand Down
2 changes: 0 additions & 2 deletions lib/src/impl_js/impl_js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: non_constant_identifier_names

library impl_js;

import 'dart:async';
Expand Down
Loading

0 comments on commit 558bbab

Please sign in to comment.