root/apps/outlook/trunk/DotTel/BouncyCastle/src/asn1/ocsp/Signature.cs
@
20
| Revision 20, 2.8 kB (checked in by root, 5 years ago) |
|---|
| Line | |
|---|---|
| 1 | using System; |
| 2 | |
| 3 | using Org.BouncyCastle.Asn1; |
| 4 | using Org.BouncyCastle.Asn1.X509; |
| 5 | |
| 6 | namespace Org.BouncyCastle.Asn1.Ocsp |
| 7 | { |
| 8 | public class Signature |
| 9 | : Asn1Encodable |
| 10 | { |
| 11 | internal AlgorithmIdentifier signatureAlgorithm; |
| 12 | internal DerBitString signatureValue; |
| 13 | internal Asn1Sequence certs; |
| 14 | |
| 15 | public static Signature GetInstance( |
| 16 | Asn1TaggedObject obj, |
| 17 | bool explicitly) |
| 18 | { |
| 19 | return GetInstance(Asn1Sequence.GetInstance(obj, explicitly)); |
| 20 | } |
| 21 | |
| 22 | public static Signature GetInstance( |
| 23 | object obj) |
| 24 | { |
| 25 | if (obj == null || obj is Signature) |
| 26 | { |
| 27 | return (Signature)obj; |
| 28 | } |
| 29 | |
| 30 | if (obj is Asn1Sequence) |
| 31 | { |
| 32 | return new Signature((Asn1Sequence)obj); |
| 33 | } |
| 34 | |
| 35 | throw new ArgumentException("unknown object in factory: " + obj.GetType().Name, "obj"); |
| 36 | } |
| 37 | |
| 38 | public Signature( |
| 39 | AlgorithmIdentifier signatureAlgorithm, |
| 40 | DerBitString signatureValue) |
| 41 | : this(signatureAlgorithm, signatureValue, null) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | public Signature( |
| 46 | AlgorithmIdentifier signatureAlgorithm, |
| 47 | DerBitString signatureValue, |
| 48 | Asn1Sequence certs) |
| 49 | { |
| 50 | if (signatureAlgorithm == null) |
| 51 | throw new ArgumentException("signatureAlgorithm"); |
| 52 | if (signatureValue == null) |
| 53 | throw new ArgumentException("signatureValue"); |
| 54 | |
| 55 | this.signatureAlgorithm = signatureAlgorithm; |
| 56 | this.signatureValue = signatureValue; |
| 57 | this.certs = certs; |
| 58 | } |
| 59 | |
| 60 | private Signature( |
| 61 | Asn1Sequence seq) |
| 62 | { |
| 63 | signatureAlgorithm = AlgorithmIdentifier.GetInstance(seq[0]); |
| 64 | signatureValue = (DerBitString)seq[1]; |
| 65 | |
| 66 | if (seq.Count == 3) |
| 67 | { |
| 68 | certs = Asn1Sequence.GetInstance( |
| 69 | (Asn1TaggedObject)seq[2], true); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | public AlgorithmIdentifier SignatureAlgorithm |
| 74 | { |
| 75 | get { return signatureAlgorithm; } |
| 76 | } |
| 77 | |
| 78 | public DerBitString SignatureValue |
| 79 | { |
| 80 | get { return signatureValue; } |
| 81 | } |
| 82 | |
| 83 | public Asn1Sequence Certs |
| 84 | { |
| 85 | get { return certs; } |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Produce an object suitable for an Asn1OutputStream. |
| 90 | * <pre> |
| 91 | * Signature ::= Sequence { |
| 92 | * signatureAlgorithm AlgorithmIdentifier, |
| 93 | * signature BIT STRING, |
| 94 | * certs [0] EXPLICIT Sequence OF Certificate OPTIONAL} |
| 95 | * </pre> |
| 96 | */ |
| 97 | public override Asn1Object ToAsn1Object() |
| 98 | { |
| 99 | Asn1EncodableVector v = new Asn1EncodableVector( |
| 100 | signatureAlgorithm, signatureValue); |
| 101 | |
| 102 | if (certs != null) |
| 103 | { |
| 104 | v.Add(new DerTaggedObject(true, 0, certs)); |
| 105 | } |
| 106 | |
| 107 | return new DerSequence(v); |
| 108 | } |
| 109 | } |
| 110 | } |
Note: See TracBrowser
for help on using the browser.








