Class SignatureBase

java.lang.Object
com.authlete.hms.SignatureBase

public class SignatureBase extends Object
A class representing signature-base defined in RFC 9421 HTTP Message Signatures, Section 2.5. Creating the Signature Base.
See Also:
  • Constructor Details

    • SignatureBase

      public SignatureBase(List<SignatureBaseLine> baseLines, SignatureParamsLine paramsLine)
      A constructor with signature base lines and a signature params line.
      Parameters:
      baseLines - Signature base lines.
      paramsLine - A signature params line. Must not be null.
      Throws:
      IllegalArgumentException - The signature params line is null.
  • Method Details

    • toString

      public String toString()
      Get the string representation of this instance, which is the serialized signature base returned by the serialize() method.
      Overrides:
      toString in class Object
      Returns:
      The string representation of this instance.
    • serialize

      public String serialize()
      Serialize the signature base represented by this instance, and return the resulting string.
      Returns:
      The serialized signature base represented by this instance.
    • serializeTo

      public StringBuilder serializeTo(StringBuilder sb)
      Serialize the signature base represented by this instance, and write the resulting string into the specified string builder.

      The ABNF for signature base from RFC 9421 HTTP Message Signatures, 2.5. Creating the Signature Base:

       signature-base = *( signature-base-line LF ) signature-params-line
       signature-base-line = component-identifier ":" SP
           ( derived-component-value / *field-content )
           ; no obs-fold nor obs-text
       component-identifier = component-name parameters
       component-name = sf-string
       derived-component-value = *( VCHAR / SP )
       signature-params-line = DQUOTE "@signature-params" DQUOTE
            ":" SP inner-list
       
      Parameters:
      sb - A string builder into which the resulting string is written.
      Returns:
      The same string builder that was passed as the argument.
    • getBaseLines

      public List<SignatureBaseLine> getBaseLines()
      Get the signature base lines included in this signature base.
      Returns:
      The signature base lines.
    • getParamsLine

      public SignatureParamsLine getParamsLine()
      Get the signature params line included in this signature base.
      Returns:
      The signature params line.
    • sign

      public byte[] sign(HttpSigner signer) throws SignatureException
      Sign this signature base (= create a signature for this signature base).
      Parameters:
      signer - A signer that signs the signature base.
      Returns:
      A newly generated signature.
      Throws:
      SignatureException - The signing operation failed.
    • verify

      public boolean verify(HttpVerifier verifier, byte[] signature) throws SignatureException
      Verify the signature.
      Parameters:
      verifier - A verifier that verifies the signature.
      signature - A signature.
      Returns:
      True if the signature is valid.
      Throws:
      SignatureException - Signature verification failed, or the signature is invalid.