001: // CMP implementation copyright (c) 2003 NOVOSEC AG (http://www.novosec.com)
002: //
003: // Author: Maik Stohn
004: //
005: // Permission is hereby granted, free of charge, to any person obtaining a copy of this
006: // software and associated documentation files (the "Software"), to deal in the Software
007: // without restriction, including without limitation the rights to use, copy, modify, merge,
008: // publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
009: // to whom the Software is furnished to do so, subject to the following conditions:
010: //
011: // The above copyright notice and this permission notice shall be included in all copies or
012: // substantial portions of the Software.
013: //
014: // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
015: // BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
016: // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
017: // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
018: // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
019:
020: package com.novosec.pkix.asn1.crmf;
021:
022: import org.bouncycastle.asn1.ASN1EncodableVector;
023: import org.bouncycastle.asn1.ASN1Sequence;
024: import org.bouncycastle.asn1.ASN1TaggedObject;
025: import org.bouncycastle.asn1.DEREncodable;
026: import org.bouncycastle.asn1.DERInteger;
027: import org.bouncycastle.asn1.DERObject;
028: import org.bouncycastle.asn1.DEROctetString;
029: import org.bouncycastle.asn1.DERSequence;
030: import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
031:
032: /**
033: * ASN.1 structure DER En/DeCoder.
034: *
035: * <pre>
036: * PBMParameter ::= SEQUENCE {
037: * salt OCTET STRING,
038: * owf AlgorithmIdentifier, -- AlgId for a One-Way Function (SHA-1 recommended)
039: * iterationCount INTEGER, -- number of times the OWF is applied
040: * mac AlgorithmIdentifier -- the MAC AlgId (e.g., DES-MAC, Triple-DES-MAC [PKCS11],or HMAC [RFC2104, RFC2202])
041: * }
042: *
043: * </pre>
044: */
045: public class PBMParameter implements DEREncodable {
046: DEROctetString salt;
047: AlgorithmIdentifier owf;
048: DERInteger iterationCount;
049: AlgorithmIdentifier mac;
050:
051: public static PBMParameter getInstance(ASN1TaggedObject obj,
052: boolean explicit) {
053: return getInstance(ASN1Sequence.getInstance(obj, explicit));
054: }
055:
056: public static PBMParameter getInstance(Object obj) {
057: if (obj instanceof PBMParameter) {
058: return (PBMParameter) obj;
059: } else if (obj instanceof ASN1Sequence) {
060: return new PBMParameter((ASN1Sequence) obj);
061: }
062:
063: throw new IllegalArgumentException("unknown object in factory");
064: }
065:
066: public PBMParameter(ASN1Sequence seq) {
067: this .salt = (DEROctetString) seq.getObjectAt(0);
068: this .owf = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
069: this .iterationCount = DERInteger
070: .getInstance(seq.getObjectAt(2));
071: this .mac = AlgorithmIdentifier.getInstance(seq.getObjectAt(3));
072: }
073:
074: public PBMParameter(DEROctetString salt, AlgorithmIdentifier owf,
075: DERInteger iterationCount, AlgorithmIdentifier mac) {
076: this .salt = salt;
077: this .owf = owf;
078: this .iterationCount = iterationCount;
079: this .mac = mac;
080: }
081:
082: public DEROctetString getSalt() {
083: return salt;
084: }
085:
086: public AlgorithmIdentifier getOwf() {
087: return owf;
088: }
089:
090: public DERInteger getIterationCount() {
091: return iterationCount;
092: }
093:
094: public AlgorithmIdentifier getMac() {
095: return mac;
096: }
097:
098: public DERObject getDERObject() {
099: ASN1EncodableVector v = new ASN1EncodableVector();
100:
101: v.add(salt);
102: v.add(owf);
103: v.add(iterationCount);
104: v.add(mac);
105:
106: return new DERSequence(v);
107: }
108:
109: public String toString() {
110: return "PBMParameter: (salt = " + this .getSalt() + ", "
111: + "owf = " + this .getOwf() + ", " + "iterationCount = "
112: + this .getIterationCount() + ", " + "mac = "
113: + this .getMac() + ")";
114: }
115: }
|