Skip to content

Commit

Permalink
Merge pull request #50 from mootw/master
Browse files Browse the repository at this point in the history
migrate to dart 3, upgrade http, switch to 'lints' package from 'pedantic'
  • Loading branch information
rbellens committed Jul 24, 2023
2 parents e2463cd + 72b6b22 commit 88b23a1
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 33 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.3.4

- **FEAT**: Support latest `package:http` ([#50](https://github.com/appsup-dart/jose/pull/50))


## 0.3.3

- **FIX**: allow double values when converting to DateTime and Duration (pull request [#33](https://github.com/appsup-dart/jose/issues/33) from PixelToast). ([3b204b10](https://github.com/appsup-dart/jose/commit/3b204b10101c7db7dc275279dcc4090a1494d238))
Expand Down
5 changes: 1 addition & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Defines a default set of lint rules enforced for
# projects at Google. For details and rationale,
# see https://github.com/dart-lang/pedantic#enabled-lints.
include: package:pedantic/analysis_options.yaml
include: package:lints/recommended.yaml

# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
# Uncomment to specify additional rules.
Expand Down
2 changes: 2 additions & 0 deletions lib/src/jwa.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// [JSON Web Algorithms](https://tools.ietf.org/html/rfc7518)
// ignore_for_file: constant_identifier_names

library jose.jwa;

import 'package:crypto_keys/crypto_keys.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/src/jwe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class JsonWebEncryptionBuilder extends JoseObjectBuilder<JsonWebEncryption> {
'enc': encryptionAlgorithm
};

var _recipients = recipients.map((r) {
var recipientsMapped = recipients.map((r) {
var key = r['_jwk'] as JsonWebKey;
var algorithm = r['alg'] ?? key.algorithmForOperation('wrapKey') ?? 'dir';
if (algorithm == 'dir') {
Expand Down Expand Up @@ -252,7 +252,7 @@ class JsonWebEncryptionBuilder extends JoseObjectBuilder<JsonWebEncryption> {
var encryptedData = cek.encrypt(data!,
initializationVector: iv,
additionalAuthenticatedData: Uint8List.fromList(aad.codeUnits));
return JsonWebEncryption._(encryptedData.data, _recipients,
return JsonWebEncryption._(encryptedData.data, recipientsMapped,
protectedHeader: protectedHeader,
unprotectedHeader:
compact ? null : JsonObject.from(sharedUnprotectedHeaderParams),
Expand Down
8 changes: 4 additions & 4 deletions lib/src/jwk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class JsonWebKey extends JsonObject {
);
}

String _toCurveName(Identifier? curve) {
String toCurveName(Identifier? curve) {
return curvesByName.entries
.firstWhere((element) => element.value == curve)
.key;
Expand All @@ -92,7 +92,7 @@ class JsonWebKey extends JsonObject {
}

return JsonWebKey.ec(
curve: _toCurveName(privateKey.curve),
curve: toCurveName(privateKey.curve),
privateKey: privateKey.eccPrivateKey,
xCoordinate: (publicKey as EcPublicKey?)?.xCoordinate,
yCoordinate: publicKey?.yCoordinate,
Expand All @@ -115,7 +115,7 @@ class JsonWebKey extends JsonObject {

if (publicKey is EcPublicKey) {
return JsonWebKey.ec(
curve: _toCurveName(publicKey.curve),
curve: toCurveName(publicKey.curve),
xCoordinate: publicKey.xCoordinate,
yCoordinate: publicKey.yCoordinate,
keyId: keyId);
Expand Down Expand Up @@ -231,7 +231,7 @@ class JsonWebKey extends JsonObject {
///
/// Other values MAY be used.
Set<String>? get keyOperations =>
getTypedList<String>('key_ops')?.toSet() as Set<String>?;
getTypedList<String>('key_ops')?.toSet();

/// The algorithm intended for use with the key.
String? get algorithm => this['alg'];
Expand Down
8 changes: 4 additions & 4 deletions lib/src/jws.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class JsonWebSignature extends JoseObject {
/// Constructs a [JsonWebSignature] from its flattened or general JSON
/// representation
factory JsonWebSignature.fromJson(Map<String, dynamic> json) {
var signatures;
Iterable<_JwsRecipient> signatures;
if (json.containsKey('signatures')) {
signatures = json['signatures'].map((v) => _JwsRecipient.fromJson(v));
signatures = (json['signatures'] as List<Map<String, Object>>).map((v) => _JwsRecipient.fromJson(v));
} else {
signatures = [_JwsRecipient.fromJson(json)];
}
Expand Down Expand Up @@ -187,13 +187,13 @@ class JsonWebSignatureBuilder extends JoseObjectBuilder<JsonWebSignature> {
throw StateError('No payload set');
}

var _signatures = recipients.map((r) {
var signatures = recipients.map((r) {
var key = r['_jwk'];
var algorithm = r['alg'];
return _JwsRecipient._sign(payload.data, payload.protectedHeader!, key,
algorithm: algorithm, protectAll: recipients.length == 1);
}).toList();

return JsonWebSignature._(payload.data, _signatures);
return JsonWebSignature._(payload.data, signatures);
}
}
2 changes: 1 addition & 1 deletion lib/src/jwt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class JsonWebToken {
var joseObject = JoseObject.fromCompactSerialization(serialization);
var content = await joseObject.getPayload(keyStore,
allowedAlgorithms: allowedArguments);
var claims;
JsonWebTokenClaims claims;
if (content.mediaType == 'JWT') {
claims = (await decodeAndVerify(content.stringContent, keyStore,
allowedArguments: allowedArguments))
Expand Down
10 changes: 5 additions & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
name: jose
description: Javascript Object Signing and Encryption (JOSE) library supporting JWE, JWS, JWK and JWT
version: 0.3.3
version: 0.3.4
homepage: https://github.com/appsup-dart/jose
funding:
- https://github.com/sponsors/rbellens


environment:
sdk: '>=2.12.0 <3.0.0'
sdk: ^3.0.0

dependencies:
crypto_keys: ^0.3.0+1
meta: ^1.1.6
typed_data: ^1.0.0
x509: ^0.2.1
http: ^0.13.0
http: '>=0.13.0 <2.0.0'
http_parser: ^4.0.0
asn1lib: ^1.0.0
collection: ^1.15.0

dev_dependencies:
test: ^1.0.0
pedantic: ^1.9.0
test: ^1.24.4
lints: ^2.1.1

false_secrets:
- test/pem/*
Expand Down
2 changes: 1 addition & 1 deletion test/jwa_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ void main() {
var data = utf8.encode('hello world');

for (var a in JsonWebAlgorithm.allAlgorithms) {
print('${a.name}');
print(a.name);
var keyPair = a.generateCryptoKeyPair();

var key = a.jwkFromCryptoKeyPair(keyPair);
Expand Down
6 changes: 3 additions & 3 deletions test/jwe_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void _doTests(dynamic payload, dynamic key, dynamic encoded) {
: JsonWebKeySet.fromKeys(key == null ? [] : [key]);
var context = JsonWebKeyStore()..addKeySet(keys);

Future<void> _expectPayload(JsonWebEncryption jwe) async {
Future<void> expectPayload(JsonWebEncryption jwe) async {
var content = await jwe.getPayload(context);
if (payload is String) {
expect(content.stringContent, payload);
Expand All @@ -316,7 +316,7 @@ void _doTests(dynamic payload, dynamic key, dynamic encoded) {
}
});
test('decrypt', () async {
await _expectPayload(jwe);
await expectPayload(jwe);
});
test('create', () async {
var builder = JsonWebEncryptionBuilder()
Expand All @@ -338,6 +338,6 @@ void _doTests(dynamic payload, dynamic key, dynamic encoded) {
jwe = builder.build();

if (encoded is String) jwe.toCompactSerialization();
await _expectPayload(jwe);
await expectPayload(jwe);
});
}
8 changes: 4 additions & 4 deletions test/jws_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void _doTests(dynamic payload, dynamic key, dynamic encoded,
: JsonWebKeySet.fromKeys(key == null ? [] : [key]);
var context = JsonWebKeyStore()..addKeySet(keys);

Future<void> _expectPayload(
Future<void> expectPayload(
JoseObject jose, {
List<String>? allowedAlgorithms,
}) async {
Expand All @@ -244,15 +244,15 @@ void _doTests(dynamic payload, dynamic key, dynamic encoded,
}

test('decode', () {
_expectPayload(jws, allowedAlgorithms: allowedAlgorithms);
expectPayload(jws, allowedAlgorithms: allowedAlgorithms);
if (encoded is String) {
expect(jws.toCompactSerialization(), encoded);
} else {
expect(jws.toJson(), encoded);
}
});
test('verify', () async {
await _expectPayload(jws, allowedAlgorithms: allowedAlgorithms);
await expectPayload(jws, allowedAlgorithms: allowedAlgorithms);
});
test('create', () async {
var builder = JsonWebSignatureBuilder()..content = payload;
Expand All @@ -268,6 +268,6 @@ void _doTests(dynamic payload, dynamic key, dynamic encoded,
var jws = builder.build();

if (encoded is String) jws.toCompactSerialization();
await _expectPayload(jws, allowedAlgorithms: allowedAlgorithms);
await expectPayload(jws, allowedAlgorithms: allowedAlgorithms);
});
}
10 changes: 5 additions & 5 deletions test/jwt_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void main() {
'W0ITrJReOgo1cq9SbsxYawBgfp_gh6A5603k2-ZQwVK0JKSHuLFkuQ3U'
}));

void _doTests(dynamic payload, dynamic encoded, [bool verify = true]) {
void doTests(dynamic payload, dynamic encoded, [bool verify = true]) {
test('decode', () async {
var jwt = await JsonWebToken.decodeAndVerify(encoded, context,
allowedArguments: verify ? null : ['none']);
Expand All @@ -98,23 +98,23 @@ void main() {
}

group('Example JWT', () {
_doTests(
doTests(
{'iss': 'joe', 'exp': 1300819380, 'http://example.com/is_root': true},
'eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9.'
'eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt'
'cGxlLmNvbS9pc19yb290Ijp0cnVlfQ.'
'dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk');
});
group('Example Unsecured JWT', () {
_doTests(
doTests(
{'iss': 'joe', 'exp': 1300819380, 'http://example.com/is_root': true},
'eyJhbGciOiJub25lIn0.'
'eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt'
'cGxlLmNvbS9pc19yb290Ijp0cnVlfQ.',
false);
});
group('Example Encrypted JWT', () {
_doTests(
doTests(
{'iss': 'joe', 'exp': 1300819380, 'http://example.com/is_root': true},
'eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0.'
'QR1Owv2ug2WyPBnbQrRARTeEk9kDO2w8qDcjiHnSJflSdv1iNqhWXaKH4MqAkQtM'
Expand All @@ -129,7 +129,7 @@ void main() {
'fiK51VwhsxJ-siBMR-YFiA');
});
group('Example Nested JWT', () {
_doTests(
doTests(
{'iss': 'joe', 'exp': 1300819380, 'http://example.com/is_root': true},
'eyJhbGciOiJSU0ExXzUiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiY3R5IjoiSldU'
'In0.'
Expand Down

0 comments on commit 88b23a1

Please sign in to comment.