@@ -70,15 +70,15 @@ mutable struct JWT
70
70
71
71
function JWT (; jwt:: Union{Nothing,String} = nothing , payload:: Union{Nothing,Dict{String,Any},String} = nothing )
72
72
if jwt != = nothing
73
- @assert payload === nothing
73
+ ( payload === nothing ) || throw ( ArgumentError ( " payload must be nothing if jwt is provided " ))
74
74
parts = split (jwt, " ." )
75
75
if length (parts) == 3
76
76
new (parts[2 ], parts[1 ], parts[3 ], false , nothing )
77
77
else
78
78
new (" " , nothing , nothing , true , false )
79
79
end
80
80
else
81
- @assert payload != = nothing
81
+ ( payload != = nothing ) || throw ( ArgumentError ( " payload must be provided if jwt is not " ))
82
82
new (isa (payload, String) ? payload : urlenc (base64encode (JSON. json (payload))), nothing , nothing , false , nothing )
83
83
end
84
84
end
@@ -109,10 +109,10 @@ isvalid(jwt::JWT) = jwt.valid
109
109
110
110
Get the key id from the JWT header, or `nothing` if the `kid` parameter is not included in the JWT header.
111
111
112
- The JWT must be signed. An `AssertionError` is thrown otherwise.
112
+ The JWT must be signed. An exception is thrown otherwise.
113
113
"""
114
114
function kid (jwt:: JWT ):: String
115
- @assert issigned (jwt)
115
+ issigned (jwt) || throw ( ArgumentError ( " jwt is not signed " ) )
116
116
get (decodepart (jwt. header), " kid" , nothing )
117
117
end
118
118
@@ -121,10 +121,10 @@ end
121
121
122
122
Get the key algorithm from the JWT header, or `nothing` if the `alg` parameter is not included in the JWT header.
123
123
124
- The JWT must be signed. An `AssertionError` is thrown otherwise.
124
+ The JWT must be signed. An exception is thrown otherwise.
125
125
"""
126
126
function alg (jwt:: JWT ):: String
127
- @assert issigned (jwt)
127
+ issigned (jwt) || throw ( ArgumentError ( " jwt is not signed " ) )
128
128
get (decodepart (jwt. header), " alg" , nothing )
129
129
end
130
130
@@ -150,7 +150,7 @@ show(io::IO, jwt::JWT) = print(io, issigned(jwt) ? join([jwt.header, jwt.payload
150
150
validate!(jwt, keyset)
151
151
152
152
Validate the JWT using the keys in the keyset.
153
- The JWT must be signed. An `AssertionError` is thrown otherwise.
153
+ The JWT must be signed. An exception is thrown otherwise.
154
154
The keyset must contain the key id from the JWT header. A KeyError is thrown otherwise.
155
155
156
156
Returns `true` if the JWT is valid, `false` otherwise.
@@ -163,7 +163,7 @@ function validate!(jwt::JWT, keyset::JWKSet, kid::String)
163
163
end
164
164
function validate! (jwt:: JWT , key:: JWK )
165
165
isverified (jwt) && (return isvalid (jwt))
166
- @assert issigned (jwt)
166
+ issigned (jwt) || throw ( ArgumentError ( " jwt is not signed " ) )
167
167
168
168
data = jwt. header * " ." * jwt. payload
169
169
sigbytes = base64decode (urldec (jwt. signature))
0 commit comments