From: <ed...@mx...> - 2003-02-04 13:13:58
|
edwin 03/02/04 08:22:03 Modified: openpgp/src/cryptix/openpgp/provider PGPCertificateImpl.java Log: Parse the signature subpackets on demand. Revision Changes Path 1.3 +26 -4 projects/openpgp/src/cryptix/openpgp/provider/PGPCertificateImpl.java Index: PGPCertificateImpl.java =================================================================== RCS file: /home/cryptix-cvs/cvsroot/projects/openpgp/src/cryptix/openpgp/provider/PGPCertificateImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- PGPCertificateImpl.java 3 Feb 2003 15:04:00 -0000 1.2 +++ PGPCertificateImpl.java 4 Feb 2003 13:22:03 -0000 1.3 @@ -1,4 +1,4 @@ -/* $Id: PGPCertificateImpl.java,v 1.2 2003/02/03 15:04:00 edwin Exp $ +/* $Id: PGPCertificateImpl.java,v 1.3 2003/02/04 13:22:03 edwin Exp $ * * Copyright (C) 1999-2001 The Cryptix Foundation Limited. * All rights reserved. @@ -14,6 +14,7 @@ import cryptix.openpgp.PGPCertificate; import cryptix.openpgp.PGPDataFormatException; +import cryptix.openpgp.PGPFatalDataFormatException; import cryptix.openpgp.PGPKey; import cryptix.openpgp.PGPPrincipal; import cryptix.openpgp.PGPPublicKey; @@ -32,6 +33,7 @@ import cryptix.openpgp.signature.PGPBooleanSP; import cryptix.openpgp.signature.PGPDateSP; import cryptix.openpgp.signature.PGPKeyFlagsSP; +import cryptix.openpgp.signature.PGPKeyIDSP; import cryptix.openpgp.signature.PGPNotationDataSP; import cryptix.openpgp.signature.PGPSignatureSubPacket; import cryptix.openpgp.signature.PGPStringSP; @@ -68,7 +70,7 @@ * An OpenPGP Certificate. * * @author Edwin Woudt <ed...@cr...> - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ public class PGPCertificateImpl extends PGPCertificate { @@ -136,13 +138,13 @@ PGPPrincipal subject, PGPPublicKey key) { super("OpenPGP"); + this.pkt = pkt; this.subject = subject; this.key = key; } - // Methods from java.security.cert.Certificate // and cryptix.pki.ExtendedCertificate // .......................................................................... @@ -386,10 +388,29 @@ } + private boolean parsed = false; + + /** Helper method to parse the signature subpackets if necessairy */ + private void parse() + throws CertificateParsingException + { + try { + if (parsed) return; + if (pkt.getVersion() > 3) pkt.parseSignatureSubPackets(); + parsed = true; + } catch (PGPDataFormatException pdfe) { + throw new CertificateParsingException(""+pdfe); + } catch (PGPFatalDataFormatException pfdfe) { + throw new CertificateParsingException(""+pfdfe); + } + } + + /** helper method for getting hashed packets */ private PGPSignatureSubPacket getPacket(byte ID) throws CertificateParsingException { + parse(); if (pkt.getVersion() == 3) return null; if (pkt.getVersion() != 4) { throw new CertificateParsingException( @@ -434,6 +455,7 @@ private PGPSignatureSubPacket getUnhashedPacket(byte ID) throws CertificateParsingException { + parse(); if (pkt.getVersion() == 3) return null; if (pkt.getVersion() != 4) { throw new CertificateParsingException( @@ -756,7 +778,7 @@ if (sp == null) { cachedIssuerKeyID = null; } else { - byte[] keyid = ((PGPByteArraySP)sp).getValue(); + byte[] keyid = ((PGPKeyIDSP)sp).getValue(); cachedIssuerKeyID = new PGPKeyIDImpl(null, keyid, 4); } |