JWT: updated to make JWT algorithm support more flexible, and simple to extend with specific algorithm.
This commit is contained in:
98
library/security/jwt/src/jwt_algorithms.e
Normal file
98
library/security/jwt/src/jwt_algorithms.e
Normal file
@@ -0,0 +1,98 @@
|
||||
note
|
||||
description: "Summary description for {JWT_ALGORITHMS}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
JWT_ALGORITHMS
|
||||
|
||||
inherit
|
||||
ANY
|
||||
redefine
|
||||
default_create
|
||||
end
|
||||
|
||||
create
|
||||
default_create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
do
|
||||
create items.make_caseless (2)
|
||||
register_algorithm (hs256)
|
||||
register_algorithm (none)
|
||||
-- TODO: check if this is acceptable default.
|
||||
set_default_algorithm ({JWT_ALG_HS256}.name)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
hs256: JWT_ALG_HS256
|
||||
do
|
||||
create Result
|
||||
end
|
||||
|
||||
none: JWT_ALG_NONE
|
||||
do
|
||||
create Result
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
default_algorithm: JWT_ALG
|
||||
do
|
||||
if attached internal_default_alg_name as l_alg_name then
|
||||
Result := algorithm (l_alg_name)
|
||||
end
|
||||
if Result = Void then
|
||||
Result := none
|
||||
end
|
||||
end
|
||||
|
||||
algorithm alias "[]" (a_name: READABLE_STRING_GENERAL): detachable JWT_ALG
|
||||
do
|
||||
Result := items [a_name]
|
||||
end
|
||||
|
||||
feature -- Element change
|
||||
|
||||
register_algorithm (alg: attached like algorithm)
|
||||
do
|
||||
items [alg.name] := alg
|
||||
end
|
||||
|
||||
unregister_algorithm (a_alg_name: READABLE_STRING_GENERAL)
|
||||
do
|
||||
items.remove (a_alg_name)
|
||||
end
|
||||
|
||||
set_default_algorithm (a_alg_name: detachable READABLE_STRING_GENERAL)
|
||||
do
|
||||
if
|
||||
a_alg_name = Void or else
|
||||
not is_supported_algorithm (a_alg_name)
|
||||
then
|
||||
internal_default_alg_name := Void
|
||||
else
|
||||
internal_default_alg_name := a_alg_name
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
is_supported_algorithm (a_name: READABLE_STRING_GENERAL): BOOLEAN
|
||||
do
|
||||
Result := items.has (a_name)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
items: STRING_TABLE [attached like algorithm]
|
||||
|
||||
internal_default_alg_name: detachable READABLE_STRING_GENERAL
|
||||
|
||||
invariant
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user