ByteArrayInputStream bis =
new ByteArrayInputStream(certBuf.getArray(), certBuf.getArrayOffset(),
certBuf.getLength());
CryptoService crypto = Crypto.getCryptoService();
try {
try {
pubKey = crypto.readPublicKey(self.algorithm.getKeyFormat(), bis);
} catch (CryptoException ce) {
// It might not be a key
}
if (pubKey == null) {
bis.reset();
try {
KeyPair pair = crypto.readKeyPair(self.algorithm.getKeyFormat(), bis, null);
pubKey = pair.getPublic();
} catch (CryptoException ce) {
// And it might not be a key pair either
}
}
if (pubKey == null) {
bis.reset();
cert = crypto.readCertificate(bis);
if (cert == null) {
throw Utils.makeError(cx, thisObj, "no certificates available");
}
}