Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parsing jws from json #7

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.6

- **FIX**: parsing jws from json. ([05c04f43](https://github.com/appsup-dart/jose/commit/05c04f4329d1ea0fbe54ab57b7ecb602fc541635))


## 0.4.5

Expand Down
12 changes: 8 additions & 4 deletions lib/src/jws.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ class JsonWebSignature extends JoseObject {
/// representation
factory JsonWebSignature.fromJson(Map<String, dynamic> json) {
Iterable<_JwsRecipient> signatures;
if (json.containsKey('signatures')) {
signatures = (json['signatures'] as List<Map<String, Object>>)
final rawSignatures = json['signatures'] as List<dynamic>?;
if (rawSignatures != null) {
signatures = rawSignatures
.whereType<Map<String, dynamic>>()
.map((v) => _JwsRecipient.fromJson(v));
} else {
signatures = [_JwsRecipient.fromJson(json)];
}
return JsonWebSignature._(decodeBase64EncodedBytes(json['payload']),
List.unmodifiable(signatures));
return JsonWebSignature._(
decodeBase64EncodedBytes(json['payload']),
List.unmodifiable(signatures),
);
}

@override
Expand Down
6 changes: 2 additions & 4 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ ide:
command:
version:
linkToCommits: true
workspaceChangelog: false

scripts:
preversion:
exec: dart test -j 1



exec: dart test -j 1
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: jose_plus
description: Javascript Object Signing and Encryption (JOSE) library supporting JWE, JWS, JWK and JWT
version: 0.4.5
version: 0.4.6
homepage: https://github.com/Bdaya-Dev/jose
funding:
- https://github.com/sponsors/rbellens
Expand Down
32 changes: 32 additions & 0 deletions test/jws_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:jose_plus/jose.dart';
import 'package:test/test.dart';

Expand Down Expand Up @@ -255,6 +257,36 @@ void main() {
final isVerified = await jws.verify(keyStore);
expect(isVerified, isTrue);
});
test('appsub-dart/jose#57', () async {
final testData = {
'payload':
'eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGF'
'tcGxlLmNvbS9pc19yb290Ijp0cnVlfQ',
'signatures': [
{
'protected': 'eyJhbGciOiJSUzI1NiJ9',
'header': {'kid': '2010-12-29'},
'signature': 'cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZ'
'mh7AAuHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjb'
'KBYNX4BAynRFdiuB--f_nZLgrnbyTyWzO75vRK5h6xBArLIARNPvkSjtQBMHl'
'b1L07Qe7K0GarZRmB_eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZES'
'c6BfI7noOPqvhJ1phCnvWh6IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AX'
'LIhWkWywlVmtVrBp0igcN_IoypGlUPQGe77Rw'
},
{
'protected': 'eyJhbGciOiJFUzI1NiJ9',
'header': {'kid': 'e9bc097a-ce51-4036-9562-d2ade882db0d'},
'signature':
'DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDxw5djxLa8IS'
'lSApmWQxfKTUJqPP3-Kg6NU1Q'
}
]
};
final jsonJWS = jsonEncode(testData);
final jwsMap = jsonDecode(jsonJWS) as Map<String, dynamic>;
final jws = JsonWebSignature.fromJson(jwsMap);
expect(jws.recipients, isNotEmpty);
});
});
}

Expand Down