{******************************************************************************}
{                                                                              }
{  Delphi JOSE Library                                                         }
{  Copyright (c) 2015 Paolo Rossi                                              }
{  https://github.com/paolo-rossi/delphi-jose-jwt                              }
{                                                                              }
{******************************************************************************}
{                                                                              }
{  Licensed under the Apache License, Version 2.0 (the "License");             }
{  you may not use this file except in compliance with the License.            }
{  You may obtain a copy of the License at                                     }
{                                                                              }
{      http://www.apache.org/licenses/LICENSE-2.0                              }
{                                                                              }
{  Unless required by applicable law or agreed to in writing, software         }
{  distributed under the License is distributed on an "AS IS" BASIS,           }
{  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.    }
{  See the License for the specific language governing permissions and         }
{  limitations under the License.                                              }
{                                                                              }
{******************************************************************************}

/// <summary>
///   Token Parts
/// </summary>
unit Bcl.Jose.Core.Parts;

{$IF CompilerVersion >= 24.0}
  {$LEGACYIFEND ON}
{$IFEND}

interface

{$IF CompilerVersion >=27.0}

uses
  System.SysUtils,
  System.Generics.Collections,
  Bcl.Jose.Types.Bytes,
  Bcl.Jose.Core.JWT;

type
  TJOSEParts = class
  protected
    FParts: TList<TJOSEBytes>;
    FToken: TJWT;
    function GetCompactToken: TJOSEBytes; virtual; abstract;
    procedure SetCompactToken(const Value: TJOSEBytes); virtual; abstract;
  public
    constructor Create(AToken: TJWT); virtual;
    destructor Destroy; override;

    procedure Clear;
    procedure Empty;
    property CompactToken: TJOSEBytes read GetCompactToken write SetCompactToken;
  end;

{$IFEND}

implementation

{$IF CompilerVersion >=27.0}

{ TJOSEParts }

procedure TJOSEParts.Clear;
begin
  FParts.Clear;
end;

constructor TJOSEParts.Create(AToken: TJWT);
begin
  FToken := AToken;
  FParts := TList<TJOSEBytes>.Create;
end;

destructor TJOSEParts.Destroy;
begin
  FParts.Free;
  inherited;
end;

procedure TJOSEParts.Empty;
var
  LIndex: Integer;
begin
  for LIndex := 0 to FParts.Count - 1 do
    FParts[LIndex] := TJOSEBytes.Empty;
end;

{$IFEND}

end.
