Record Class Nonce

java.lang.Object
java.lang.Record
org.htmlunit.csp.value.Nonce
Record Components:
base64ValuePart - the Base64-encoded nonce value (case-sensitive)

public record Nonce(String base64ValuePart) extends Record
Represents a CSP nonce-source value, e.g. 'nonce-abc123...'.

A nonce-source consists of the keyword prefix nonce- followed by a Base64-encoded value, all enclosed in single quotes. The prefix is parsed case-insensitively, but the Base64 nonce value itself is case-sensitive.

Author:
Salvation Team
See Also:
  • Constructor Details

    • Nonce

      public Nonce(String base64ValuePart)
      Creates an instance of a Nonce record class.
      Parameters:
      base64ValuePart - the value for the base64ValuePart record component
  • Method Details

    • parseNonce

      public static Optional<Nonce> parseNonce(String value)
      Parses a nonce-source from its CSP string representation.

      The input must be a single-quoted string of the form 'nonce-<base64>'. The prefix is matched case-insensitively; the Base64 portion is preserved as-is.

      Parameters:
      value - the CSP nonce-source token (e.g. 'nonce-abc123...')
      Returns:
      an Optional containing the parsed Nonce, or empty if the value does not match the nonce-source grammar
    • toString

      public String toString()
      Returns the CSP string representation of this nonce-source, e.g. 'nonce-abc123...'.
      Specified by:
      toString in class Record
      Returns:
      the single-quoted nonce-source string
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • base64ValuePart

      public String base64ValuePart()
      Returns the value of the base64ValuePart record component.
      Returns:
      the value of the base64ValuePart record component