File tree Expand file tree Collapse file tree 4 files changed +18
-15
lines changed Expand file tree Collapse file tree 4 files changed +18
-15
lines changed Original file line number Diff line number Diff line change 11import 'dart:math' ;
22import 'dart:typed_data' ;
33
4- import 'package:crypto/crypto.dart' ;
54import 'package:ed25519_edwards/ed25519_edwards.dart' as ed;
65import 'package:pointycastle/pointycastle.dart' as pc;
76
@@ -148,12 +147,10 @@ class HMACAlgorithm extends JWTAlgorithm {
148147
149148 final keyBytes = decodeHMACSecret (secretKey.key, secretKey.isBase64Encoded);
150149
151- final hmac = Hmac (
152- _getHash (name),
153- keyBytes,
154- );
150+ final hmac = pc.Mac ('${_getHash (name )}/HMAC' );
151+ hmac.init (pc.KeyParameter (keyBytes));
155152
156- return Uint8List .fromList (hmac.convert (body).bytes );
153+ return Uint8List .fromList (hmac.process (body));
157154 }
158155
159156 @override
@@ -171,14 +168,14 @@ class HMACAlgorithm extends JWTAlgorithm {
171168 return true ;
172169 }
173170
174- Hash _getHash (String name) {
171+ String _getHash (String name) {
175172 switch (name) {
176173 case 'HS256' :
177- return sha256 ;
174+ return 'SHA-256' ;
178175 case 'HS384' :
179- return sha384 ;
176+ return 'SHA-384' ;
180177 case 'HS512' :
181- return sha512 ;
178+ return 'SHA-512' ;
182179 default :
183180 throw ArgumentError .value (name, 'name' , 'unknown hash name' );
184181 }
Original file line number Diff line number Diff line change @@ -159,3 +159,13 @@ ECDSAAlgorithm? ecCurveToAlgorithm(String curveName) {
159159 return null ;
160160 }
161161}
162+
163+ bool isListEquals <T >(List <T >? a, List <T >? b) {
164+ if (identical (a, b)) return true ;
165+ if (a == null || b == null ) return false ;
166+ if (a.length != b.length) return false ;
167+ for (var i = 0 ; i < a.length; i++ ) {
168+ if (a[i] != b[i]) return false ;
169+ }
170+ return true ;
171+ }
Original file line number Diff line number Diff line change @@ -2,8 +2,6 @@ import 'dart:collection';
22import 'dart:convert' ;
33import 'dart:typed_data' ;
44
5- import 'package:collection/collection.dart' ;
6-
75import 'algorithms.dart' ;
86import 'exceptions.dart' ;
97import 'helpers.dart' ;
@@ -112,7 +110,7 @@ class JWT {
112110 if (payload['aud' ] is String && payload['aud' ] != audience.first) {
113111 throw JWTInvalidException ('invalid audience' );
114112 } else if (payload['aud' ] is List &&
115- ! ListEquality (). equals (payload['aud' ], audience)) {
113+ ! isListEquals (payload['aud' ], audience)) {
116114 throw JWTInvalidException ('invalid audience' );
117115 }
118116 } else {
Original file line number Diff line number Diff line change @@ -13,10 +13,8 @@ false_secrets:
1313 - /README.md
1414
1515dependencies :
16- crypto : ^3.0.6
1716 pointycastle : ^4.0.0
1817 convert : ^3.1.2
19- collection : ^1.17.1
2018 ed25519_edwards : ^0.3.1
2119 clock : ^1.1.2
2220
You can’t perform that action at this time.
0 commit comments