org.bouncycastle.gpg.keybox.KeyBox Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcpg-jdk15on Show documentation
Show all versions of bcpg-jdk15on Show documentation
The Bouncy Castle Java API for handling the OpenPGP protocol. This jar contains the OpenPGP API for JDK 1.5 to JDK 1.7. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs.
package org.bouncycastle.gpg.keybox;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
/**
* KeyBox provides an implementation of the PGP keybox.
*/
public class KeyBox
{
private final FirstBlob firstBlob;
private final List keyBlobs;
public KeyBox(InputStream input, KeyFingerPrintCalculator keyFingerPrintCalculator, BlobVerifier blobVerifier)
throws IOException
{
this(KeyBoxByteBuffer.wrap(input), keyFingerPrintCalculator, blobVerifier);
}
public KeyBox(byte[] encoding, KeyFingerPrintCalculator keyFingerPrintCalculator, BlobVerifier blobVerifier)
throws IOException
{
this(KeyBoxByteBuffer.wrap(encoding), keyFingerPrintCalculator, blobVerifier);
}
private KeyBox(KeyBoxByteBuffer buffer, KeyFingerPrintCalculator keyFingerPrintCalculator, BlobVerifier blobVerifier)
throws IOException
{
Blob blob = Blob.getInstance(buffer, keyFingerPrintCalculator, blobVerifier);
if (blob == null)
{
throw new IOException("No first blob, is the source zero length?");
}
if (!(blob instanceof FirstBlob))
{
throw new IOException("First blob is not KeyBox 'First Blob'.");
}
FirstBlob firstBlob = (FirstBlob)blob;
ArrayList keyBoxEntries = new ArrayList();
for (Blob materialBlob = Blob.getInstance(buffer, keyFingerPrintCalculator, blobVerifier);
materialBlob != null; materialBlob = Blob.getInstance(buffer, keyFingerPrintCalculator, blobVerifier))
{
if (materialBlob.getType() == BlobType.FIRST_BLOB)
{
throw new IOException("Unexpected second 'FirstBlob', there should only be one FirstBlob at the start of the file.");
}
keyBoxEntries.add((KeyBlob)materialBlob);
}
this.firstBlob = firstBlob;
this.keyBlobs = Collections.unmodifiableList(keyBoxEntries);
}
public FirstBlob getFirstBlob()
{
return firstBlob;
}
public List getKeyBlobs()
{
return keyBlobs;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy