1 package org.bouncycastle.asn1.bc; 2 3 import java.math.BigInteger; 4 import java.util.Date; 5 6 import org.bouncycastle.asn1.ASN1EncodableVector; 7 import org.bouncycastle.asn1.ASN1GeneralizedTime; 8 import org.bouncycastle.asn1.ASN1Integer; 9 import org.bouncycastle.asn1.ASN1Object; 10 import org.bouncycastle.asn1.ASN1Primitive; 11 import org.bouncycastle.asn1.ASN1Sequence; 12 import org.bouncycastle.asn1.DERGeneralizedTime; 13 import org.bouncycastle.asn1.DERSequence; 14 import org.bouncycastle.asn1.DERUTF8String; 15 import org.bouncycastle.asn1.x509.AlgorithmIdentifier; 16 17 /** 18 * <pre> 19 * ObjectStoreData ::= SEQUENCE { 20 * version INTEGER. 21 * dataSalt OCTET STRING, 22 * integrityAlgorithm AlgorithmIdentifier, 23 * creationDate GeneralizedTime, 24 * lastModifiedDate GeneralizedTime, 25 * objectDataSequence ObjectDataSequence, 26 * comment UTF8String OPTIONAL 27 * } 28 * </pre> 29 */ 30 public class ObjectStoreData 31 extends ASN1Object 32 { 33 private final BigInteger version; 34 private final AlgorithmIdentifier integrityAlgorithm; 35 private final ASN1GeneralizedTime creationDate; 36 private final ASN1GeneralizedTime lastModifiedDate; 37 private final ObjectDataSequence objectDataSequence; 38 private final String comment; 39 ObjectStoreData(AlgorithmIdentifier integrityAlgorithm, Date creationDate, Date lastModifiedDate, ObjectDataSequence objectDataSequence, String comment)40 public ObjectStoreData(AlgorithmIdentifier integrityAlgorithm, Date creationDate, Date lastModifiedDate, ObjectDataSequence objectDataSequence, String comment) 41 { 42 this.version = BigInteger.valueOf(1); 43 this.integrityAlgorithm = integrityAlgorithm; 44 this.creationDate = new DERGeneralizedTime(creationDate); 45 this.lastModifiedDate = new DERGeneralizedTime(lastModifiedDate); 46 this.objectDataSequence = objectDataSequence; 47 this.comment = comment; 48 } 49 ObjectStoreData(ASN1Sequence seq)50 private ObjectStoreData(ASN1Sequence seq) 51 { 52 this.version = ASN1Integer.getInstance(seq.getObjectAt(0)).getValue(); 53 this.integrityAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(1)); 54 this.creationDate = ASN1GeneralizedTime.getInstance(seq.getObjectAt(2)); 55 this.lastModifiedDate = ASN1GeneralizedTime.getInstance(seq.getObjectAt(3)); 56 this.objectDataSequence = ObjectDataSequence.getInstance(seq.getObjectAt(4)); 57 this.comment = (seq.size() == 6) ? DERUTF8String.getInstance(seq.getObjectAt(5)).getString() : null; 58 } 59 getInstance(Object o)60 public static ObjectStoreData getInstance(Object o) 61 { 62 if (o instanceof ObjectStoreData) 63 { 64 return (ObjectStoreData)o; 65 } 66 else if (o != null) 67 { 68 return new ObjectStoreData(ASN1Sequence.getInstance(o)); 69 } 70 71 return null; 72 } 73 getComment()74 public String getComment() 75 { 76 return comment; 77 } 78 getCreationDate()79 public ASN1GeneralizedTime getCreationDate() 80 { 81 return creationDate; 82 } 83 getIntegrityAlgorithm()84 public AlgorithmIdentifier getIntegrityAlgorithm() 85 { 86 return integrityAlgorithm; 87 } 88 getLastModifiedDate()89 public ASN1GeneralizedTime getLastModifiedDate() 90 { 91 return lastModifiedDate; 92 } 93 getObjectDataSequence()94 public ObjectDataSequence getObjectDataSequence() 95 { 96 return objectDataSequence; 97 } 98 getVersion()99 public BigInteger getVersion() 100 { 101 return version; 102 } 103 toASN1Primitive()104 public ASN1Primitive toASN1Primitive() 105 { 106 ASN1EncodableVector v = new ASN1EncodableVector(6); 107 108 v.add(new ASN1Integer(version)); 109 v.add(integrityAlgorithm); 110 v.add(creationDate); 111 v.add(lastModifiedDate); 112 v.add(objectDataSequence); 113 114 if (comment != null) 115 { 116 v.add(new DERUTF8String(comment)); 117 } 118 119 return new DERSequence(v); 120 } 121 } 122