Skip to content

Commit

Permalink
Optimization in (string) parameter passing. Fixes #28
Browse files Browse the repository at this point in the history
  • Loading branch information
paolo-rossi committed Dec 6, 2019
1 parent 6178837 commit 8c037e5
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions Source/JOSE/JOSE.Core.JWT.pas
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ TJWTClaims = class(TJOSEBase)
function GetJWTId: string;
function GetNotBefore: TDateTime;
function GetSubject: string;
procedure SetAudience(Value: string);
procedure SetExpiration(Value: TDateTime);
procedure SetIssuedAt(Value: TDateTime);
procedure SetIssuer(Value: string);
procedure SetJWTId(Value: string);
procedure SetNotBefore(Value: TDateTime);
procedure SetSubject(Value: string);
procedure SetAudience(const AValue: string);
procedure SetExpiration(AValue: TDateTime);
procedure SetIssuedAt(AValue: TDateTime);
procedure SetIssuer(const AValue: string);
procedure SetJWTId(const AValue: string);
procedure SetNotBefore(AValue: TDateTime);
procedure SetSubject(const AValue: string);

function GetHasAudience: Boolean;
function GetHasExpiration: Boolean;
Expand All @@ -107,7 +107,7 @@ TJWTClaims = class(TJOSEBase)

function ClaimExists(const AClaimName: string): Boolean;
function GetAudienceArray: TArray<string>;
procedure SetAudienceArray(const Value: TArray<string>);
procedure SetAudienceArray(const AValue: TArray<string>);
public
constructor Create; virtual;
procedure SetClaimOfType<T>(const AName: string; const AValue: T);
Expand Down Expand Up @@ -303,19 +303,19 @@ function TJWTClaims.GetSubject: string;
Result := TJSONUtils.GetJSONValue(TReservedClaimNames.SUBJECT, FJSON).AsString;
end;

procedure TJWTClaims.SetAudience(Value: string);
procedure TJWTClaims.SetAudience(const AValue: string);
var
LAudienceArray: TArray<string>;
LAudience: string;
LArray: TJSONArray;
begin
if Value.IsEmpty then
if AValue.IsEmpty then
begin
TJSONUtils.RemoveJSONNode(TReservedClaimNames.AUDIENCE, FJSON);
Exit;
end;

LAudienceArray := Value.Split([AUDIENCE_SEPARATOR]);
LAudienceArray := AValue.Split([AUDIENCE_SEPARATOR]);

if Length(LAudienceArray) > 1 then
begin
Expand All @@ -327,60 +327,60 @@ procedure TJWTClaims.SetAudience(Value: string);
end;

if (Length(LAudienceArray) = 1) then
TJSONUtils.SetJSONValueFrom<string>(TReservedClaimNames.AUDIENCE, Value, FJSON);
TJSONUtils.SetJSONValueFrom<string>(TReservedClaimNames.AUDIENCE, AValue, FJSON);
end;

procedure TJWTClaims.SetAudienceArray(const Value: TArray<string>);
procedure TJWTClaims.SetAudienceArray(const AValue: TArray<string>);
begin
Audience := string.Join(AUDIENCE_SEPARATOR, Value);
Audience := string.Join(AUDIENCE_SEPARATOR, AValue);
end;

procedure TJWTClaims.SetExpiration(Value: TDateTime);
procedure TJWTClaims.SetExpiration(AValue: TDateTime);
begin
if Value = 0 then
if AValue = 0 then
TJSONUtils.RemoveJSONNode(TReservedClaimNames.EXPIRATION, FJSON)
else
TJSONUtils.SetJSONValueFrom<TDateTime>(TReservedClaimNames.EXPIRATION, Value, FJSON);
TJSONUtils.SetJSONValueFrom<TDateTime>(TReservedClaimNames.EXPIRATION, AValue, FJSON);
end;

procedure TJWTClaims.SetIssuedAt(Value: TDateTime);
procedure TJWTClaims.SetIssuedAt(AValue: TDateTime);
begin
if Value = 0 then
if AValue = 0 then
TJSONUtils.RemoveJSONNode(TReservedClaimNames.ISSUED_AT, FJSON)
else
TJSONUtils.SetJSONValueFrom<TDateTime>(TReservedClaimNames.ISSUED_AT, Value, FJSON);
TJSONUtils.SetJSONValueFrom<TDateTime>(TReservedClaimNames.ISSUED_AT, AValue, FJSON);
end;

procedure TJWTClaims.SetIssuer(Value: string);
procedure TJWTClaims.SetIssuer(const AValue: string);
begin
if Value = '' then
if AValue = '' then
TJSONUtils.RemoveJSONNode(TReservedClaimNames.ISSUER, FJSON)
else
TJSONUtils.SetJSONValueFrom<string>(TReservedClaimNames.ISSUER, Value, FJSON);
TJSONUtils.SetJSONValueFrom<string>(TReservedClaimNames.ISSUER, AValue, FJSON);
end;

procedure TJWTClaims.SetJWTId(Value: string);
procedure TJWTClaims.SetJWTId(const AValue: string);
begin
if Value = '' then
if AValue = '' then
TJSONUtils.RemoveJSONNode(TReservedClaimNames.JWT_ID, FJSON)
else
TJSONUtils.SetJSONValueFrom<string>(TReservedClaimNames.JWT_ID, Value, FJSON);
TJSONUtils.SetJSONValueFrom<string>(TReservedClaimNames.JWT_ID, AValue, FJSON);
end;

procedure TJWTClaims.SetNotBefore(Value: TDateTime);
procedure TJWTClaims.SetNotBefore(AValue: TDateTime);
begin
if Value = 0 then
if AValue = 0 then
TJSONUtils.RemoveJSONNode(TReservedClaimNames.NOT_BEFORE, FJSON)
else
TJSONUtils.SetJSONValueFrom<TDateTime>(TReservedClaimNames.NOT_BEFORE, Value, FJSON);
TJSONUtils.SetJSONValueFrom<TDateTime>(TReservedClaimNames.NOT_BEFORE, AValue, FJSON);
end;

procedure TJWTClaims.SetSubject(Value: string);
procedure TJWTClaims.SetSubject(const AValue: string);
begin
if Value = '' then
if AValue = '' then
TJSONUtils.RemoveJSONNode(TReservedClaimNames.SUBJECT, FJSON)
else
TJSONUtils.SetJSONValueFrom<string>(TReservedClaimNames.SUBJECT, Value, FJSON);
TJSONUtils.SetJSONValueFrom<string>(TReservedClaimNames.SUBJECT, AValue, FJSON);
end;

{ TJWTHeader }
Expand Down

0 comments on commit 8c037e5

Please sign in to comment.