Skip to content

Commit e6c7132

Browse files
authored
Merge pull request #22 from noha/development
unify API for extracting and checking signature
2 parents 02dfe21 + 3c7002d commit e6c7132

3 files changed

Lines changed: 19 additions & 17 deletions

File tree

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
sign
2-
checkSignature: parts withKey: key
2+
checkSignature: aString withKey: key
3+
| tokenParts |
4+
tokenParts := $. split: aString.
35
(self
4-
signMessage:
5-
($.
6-
join:
7-
{parts first.
8-
parts second}) withKey: key)
9-
= (Base64UrlEncoder new decode: parts third base64Padded)
6+
signMessage: ($. join: (tokenParts first: 2))
7+
withKey: key)
8+
= (Base64UrlEncoder new decode: tokenParts third base64Padded)
109
ifFalse: [ Error signal: 'signature does not match' ]
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
signature
2-
checkSignature: parts
3-
2+
checkSignature: aString
3+
| token |
4+
token := (aString isString not)
5+
ifTrue: [
6+
"this seems to be the old usage handing out the parts collection so resemble"
7+
$. join: aString ]
8+
ifFalse: [ aString ].
49

5-
self protectedHeader algorithm checkSignature: parts withKey: key
10+
self protectedHeader algorithm checkSignature: token withKey: key

source/JSONWebToken-OpenSSL.package/JWARSASHA256.class/class/checkSignature.withKey..st

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
sign
2-
checkSignature: parts withKey: key
3-
| jwtHeaderAndPayload signatureByteArray publicKey |
4-
jwtHeaderAndPayload := $.
5-
join:
6-
{parts first.
7-
parts second}.
8-
signatureByteArray := parts third base64Padded base64Decoded
2+
checkSignature: aString withKey: key
3+
| jwtHeaderAndPayload signatureByteArray publicKey tokenParts |
4+
tokenParts := $. split: aString.
5+
jwtHeaderAndPayload := $. join: (tokenParts first: 2).
6+
signatureByteArray := (Base64UrlEncoder new decode: tokenParts third base64Padded)
97
asByteArray.
108
publicKey := (key includesSubstring: 'BEGIN RSA PUBLIC KEY')
119
ifTrue: [ LcEvpPublicKey setRSA: (LcRSA fromRsaPublicKeyPemString: key) ]

0 commit comments

Comments
 (0)