All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.bcpg.sig.RevocationReason Maven / Gradle / Ivy

Go to download

The Bouncy Castle Java APIs for the OpenPGP Protocol. The APIs are designed primarily to be used in conjunction with the BC LTS provider but may also be used with other providers providing cryptographic services.

The newest version!
package org.bouncycastle.bcpg.sig;

import org.bouncycastle.bcpg.SignatureSubpacket;
import org.bouncycastle.bcpg.SignatureSubpacketTags;
import org.bouncycastle.util.Strings;

/**
 * Signature Subpacket for encoding the reason why a key was revoked.
 *
 * @see 
 *     RFC4880 - Reason for Revocation
 * @see 
 *     RFC9580 - Reason for Revocation
 */
public class RevocationReason extends SignatureSubpacket
{
    public RevocationReason(boolean isCritical, boolean isLongLength, byte[] data)
    {
        super(SignatureSubpacketTags.REVOCATION_REASON, isCritical, isLongLength, data);
    }

    public RevocationReason(boolean isCritical, byte reason, String description)
    {
        super(SignatureSubpacketTags.REVOCATION_REASON, isCritical, false, createData(reason, description));
    }

    private static byte[] createData(byte reason, String description)
    {
        byte[] descriptionBytes = Strings.toUTF8ByteArray(description);
        byte[] data = new byte[1 + descriptionBytes.length];

        data[0] = reason;
        System.arraycopy(descriptionBytes, 0, data, 1, descriptionBytes.length);

        return data;
    }

    public byte getRevocationReason()
    {
        return getData()[0];
    }

    public String getRevocationDescription()
    {
        byte[] data = getData();
        if (data.length == 1)
        {
            return "";
        }

        byte[] description = new byte[data.length - 1];
        System.arraycopy(data, 1, description, 0, description.length);

        return Strings.fromUTF8ByteArray(description);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy