text
stringlengths
0
234
Text.Append ('"');
end loop;
Text.Append ("}");
return ASCII.Encode (Text).To_Stream_Element_Array;
end Thumbprint;
------------------------------------
-- Validate_Compact_Serialization --
------------------------------------
procedure Validate_Compact_Serialization
(Self : out JSON_Web_Signature'Class;
Value : League.Strings.Universal_String;
Secret : Ada.Streams.Stream_Element_Array;
Valid : out Boolean)
is
use type League.Strings.Universal_String;
function Alg return Wide_Wide_String;
function Alg return Wide_Wide_String is
begin
return Self.Header.Value (+"alg").To_String.To_Wide_Wide_String;
end Alg;
List : constant League.String_Vectors.Universal_String_Vector :=
Value.Split ('.');
Ok : Boolean;
Document : League.JSON.Documents.JSON_Document;
ASCII : constant League.Text_Codecs.Text_Codec :=
League.Text_Codecs.Codec (+"USASCII");
Encoded_Payload : League.Strings.Universal_String;
Raw_Header : League.Stream_Element_Vectors.Stream_Element_Vector;
Encoded_Header : League.Strings.Universal_String;
Text : League.Strings.Universal_String;
Signature : League.Stream_Element_Vectors.Stream_Element_Vector;
Encoded_Signature : League.Strings.Universal_String;
begin
Valid := False;
-- 1. Parse the JWS representation to extract the serialized values...
if List.Length /= 3 then
return;
end if;
Encoded_Header := List.Element (1);
Encoded_Payload := List.Element (2);
Encoded_Signature := List.Element (3);
-- 2. decode the encoded representation of the JWS Protected Header
From_Base_64_URL
(Data => Encoded_Header,
Value => Raw_Header,
Success => Ok);
if not Ok then
return;
end if;
-- 3. Verify that the resulting octet sequence is ... JSON object
Document := League.JSON.Documents.From_JSON (Raw_Header);
if not Document.Is_Object or Document.Is_Empty then
return;
end if;
Self.Header := (Document.To_JSON_Object with null record);
-- 5. Verify that the implementation understands and can process...
if not Self.Header.Value (+"alg").Is_String then
return;
elsif Alg not in "none" | "HS256"
and (Alg /= "RS256" or RS256_Validation_Link = null)
then
return;
elsif Self.Header.Critical.Length > 0 then
-- Any critical extensions are not supported here
return;
end if;
-- 6. decode the encoded representation of the JWS Payload
From_Base_64_URL
(Data => Encoded_Payload,
Value => Self.Payload,
Success => Ok);
if not Ok then
return;
end if;
-- 7. decode the encoded representation of the JWS Signature
From_Base_64_URL
(Data => Encoded_Signature,
Value => Signature,
Success => Ok);
if not Ok then
return;
end if;