Class OpenPGPDefaultPolicy

java.lang.Object
org.bouncycastle.openpgp.api.OpenPGPDefaultPolicy
All Implemented Interfaces:
OpenPGPPolicy

public class OpenPGPDefaultPolicy extends Object implements OpenPGPPolicy
  • Constructor Details

    • OpenPGPDefaultPolicy

      public OpenPGPDefaultPolicy()
  • Method Details

    • rejectHashAlgorithm

      public OpenPGPDefaultPolicy rejectHashAlgorithm(int hashAlgorithmId)
    • acceptCertificationSignatureHashAlgorithm

      public OpenPGPDefaultPolicy acceptCertificationSignatureHashAlgorithm(int hashAlgorithmId)
    • acceptCertificationSignatureHashAlgorithmUntil

      public OpenPGPDefaultPolicy acceptCertificationSignatureHashAlgorithmUntil(int hashAlgorithmId, Date until)
    • acceptDocumentSignatureHashAlgorithm

      public OpenPGPDefaultPolicy acceptDocumentSignatureHashAlgorithm(int hashAlgorithmId)
    • acceptDocumentSignatureHashAlgorithmUntil

      public OpenPGPDefaultPolicy acceptDocumentSignatureHashAlgorithmUntil(int hashAlgorithmId, Date until)
    • rejectSymmetricKeyAlgorithm

      public OpenPGPDefaultPolicy rejectSymmetricKeyAlgorithm(int symmetricKeyAlgorithmId)
    • acceptSymmetricKeyAlgorithm

      public OpenPGPDefaultPolicy acceptSymmetricKeyAlgorithm(int symmetricKeyAlgorithmId)
    • acceptSymmetricKeyAlgorithmUntil

      public OpenPGPDefaultPolicy acceptSymmetricKeyAlgorithmUntil(int symmetricKeyAlgorithmId, Date until)
    • rejectPublicKeyAlgorithm

      public OpenPGPDefaultPolicy rejectPublicKeyAlgorithm(int publicKeyAlgorithmId)
    • acceptPublicKeyAlgorithm

      public OpenPGPDefaultPolicy acceptPublicKeyAlgorithm(int publicKeyAlgorithmId)
    • acceptPublicKeyAlgorithmWithMinimalStrength

      public OpenPGPDefaultPolicy acceptPublicKeyAlgorithmWithMinimalStrength(int publicKeyAlgorithmId, int minBitStrength)
    • isAcceptableDocumentSignatureHashAlgorithm

      public boolean isAcceptableDocumentSignatureHashAlgorithm(int hashAlgorithmId, Date signatureCreationTime)
      Description copied from interface: OpenPGPPolicy
      Return true, if the given hash algorithm is - at signature creation time - an acceptable document signature hash algorithm.
      Specified by:
      isAcceptableDocumentSignatureHashAlgorithm in interface OpenPGPPolicy
      Parameters:
      hashAlgorithmId - hash algorithm ID
      signatureCreationTime - optional signature creation time
      Returns:
      true if hash algorithm is acceptable at creation time
    • isAcceptableRevocationSignatureHashAlgorithm

      public boolean isAcceptableRevocationSignatureHashAlgorithm(int hashAlgorithmId, Date signatureCreationTime)
      Description copied from interface: OpenPGPPolicy
      Return true, if the given hash algorithm is - at signature creation time - an acceptable revocation signature hash algorithm.
      Specified by:
      isAcceptableRevocationSignatureHashAlgorithm in interface OpenPGPPolicy
      Parameters:
      hashAlgorithmId - hash algorithm ID
      signatureCreationTime - optional signature creation time
      Returns:
      true if hash algorithm is acceptable at creation time
    • isAcceptableCertificationSignatureHashAlgorithm

      public boolean isAcceptableCertificationSignatureHashAlgorithm(int hashAlgorithmId, Date signatureCreationTime)
      Description copied from interface: OpenPGPPolicy
      Return true, if the given hash algorithm is - at signature creation time - an acceptable certification signature hash algorithm.
      Specified by:
      isAcceptableCertificationSignatureHashAlgorithm in interface OpenPGPPolicy
      Parameters:
      hashAlgorithmId - hash algorithm ID
      signatureCreationTime - optional signature creation time
      Returns:
      true if hash algorithm is acceptable at creation time
    • getDefaultCertificationSignatureHashAlgorithm

      public int getDefaultCertificationSignatureHashAlgorithm()
      Description copied from interface: OpenPGPPolicy
      Return the default certification signature hash algorithm ID. This is used as fallback, if negotiation of a commonly supported hash algorithm fails.
      Specified by:
      getDefaultCertificationSignatureHashAlgorithm in interface OpenPGPPolicy
      Returns:
      default certification signature hash algorithm ID
    • setDefaultCertificationSignatureHashAlgorithm

      public OpenPGPDefaultPolicy setDefaultCertificationSignatureHashAlgorithm(int hashAlgorithmId)
    • getDefaultDocumentSignatureHashAlgorithm

      public int getDefaultDocumentSignatureHashAlgorithm()
      Description copied from interface: OpenPGPPolicy
      Return the default document signature hash algorithm ID. This is used as fallback, if negotiation of a commonly supported hash algorithm fails.
      Specified by:
      getDefaultDocumentSignatureHashAlgorithm in interface OpenPGPPolicy
      Returns:
      default document signature hash algorithm ID
    • setDefaultDocumentSignatureHashAlgorithm

      public OpenPGPDefaultPolicy setDefaultDocumentSignatureHashAlgorithm(int hashAlgorithmId)
    • isAcceptableSymmetricKeyAlgorithm

      public boolean isAcceptableSymmetricKeyAlgorithm(int symmetricKeyAlgorithmId)
      Description copied from interface: OpenPGPPolicy
      Return true, if the given symmetric-key algorithm is acceptable.
      Specified by:
      isAcceptableSymmetricKeyAlgorithm in interface OpenPGPPolicy
      Parameters:
      symmetricKeyAlgorithmId - symmetric-key algorithm
      Returns:
      true if symmetric-key algorithm is acceptable
    • getDefaultSymmetricKeyAlgorithm

      public int getDefaultSymmetricKeyAlgorithm()
      Description copied from interface: OpenPGPPolicy
      Return the default symmetric-key algorithm, which is used as a fallback if symmetric encryption algorithm negotiation fails.
      Specified by:
      getDefaultSymmetricKeyAlgorithm in interface OpenPGPPolicy
      Returns:
      default symmetric-key algorithm
    • setDefaultSymmetricKeyAlgorithm

      public OpenPGPDefaultPolicy setDefaultSymmetricKeyAlgorithm(int symmetricKeyAlgorithmId)
    • isAcceptablePublicKeyStrength

      public boolean isAcceptablePublicKeyStrength(int publicKeyAlgorithmId, int bitStrength)
      Description copied from interface: OpenPGPPolicy
      Return true, if the given bitStrength is acceptable for the given public key algorithm ID.
      Specified by:
      isAcceptablePublicKeyStrength in interface OpenPGPPolicy
      Parameters:
      publicKeyAlgorithmId - ID of a public key algorithm
      bitStrength - key bit strength
      Returns:
      true if strength is acceptable
    • getMaximumDecompressedDataSize

      public long getMaximumDecompressedDataSize()
      Description copied from interface: OpenPGPPolicy
      Return the maximum number of bytes a compressed data packet may decompress to before message processing fails, or a negative value for no limit.

      An OpenPGP compressed data packet carries no decompressed-length field, so a small packet can expand into an arbitrarily large amount of data (a "decompression bomb"). The nesting limit (OpenPGPMessageInputStream.MAX_RECURSION) bounds how many compression layers a message may carry but says nothing about how much any one of them may produce, so this is the bound on the latter. It is applied per compressed data packet, as the bytes are produced, which is the only point at which decompression can usefully be stopped - a consumer counting bytes off the returned stream has already paid the cost it is trying to avoid. Exceeding it surfaces as a StreamOverflowException (an IOException) from reading the message input stream.

      This mirrors the PGPCompressedData.getDataStream() / PGPCompressedData.getDataStream(long) pair on the low-level API: the default is unbounded, and bounding it is the caller's decision, because no one limit suits every application. An application processing untrusted messages whose plaintext has a known upper bound should set one.

      Specified by:
      getMaximumDecompressedDataSize in interface OpenPGPPolicy
      Returns:
      maximum decompressed size in bytes, or a negative value for no limit
    • setMaximumDecompressedDataSize

      public OpenPGPDefaultPolicy setMaximumDecompressedDataSize(long maximumDecompressedDataSize)
      Set the maximum number of bytes a compressed data packet may decompress to. Unbounded by default, mirroring the low-level PGPCompressedData.getDataStream(); an application processing untrusted messages whose plaintext has a known upper bound should set one. A negative value restores the unbounded behaviour.
      Parameters:
      maximumDecompressedDataSize - maximum decompressed size in bytes
      Returns:
      this
    • getNotationRegistry

      public OpenPGPPolicy.OpenPGPNotationRegistry getNotationRegistry()
      Description copied from interface: OpenPGPPolicy
      Return the policies OpenPGPPolicy.OpenPGPNotationRegistry containing known notation names.
      Specified by:
      getNotationRegistry in interface OpenPGPPolicy
      Returns:
      notation registry