/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.geronimo.crypto.asn1.x509;
import org.apache.geronimo.crypto.asn1.ASN1Encodable;
import org.apache.geronimo.crypto.asn1.ASN1EncodableVector;
import org.apache.geronimo.crypto.asn1.ASN1Sequence;
import org.apache.geronimo.crypto.asn1.ASN1TaggedObject;
import org.apache.geronimo.crypto.asn1.DEREncodable;
import org.apache.geronimo.crypto.asn1.DERObject;
import org.apache.geronimo.crypto.asn1.DERObjectIdentifier;
import org.apache.geronimo.crypto.asn1.DERSequence;
public class AlgorithmIdentifier
extends ASN1Encodable
{
private DERObjectIdentifier objectId;
private DEREncodable parameters;
private boolean parametersDefined = false;
public static AlgorithmIdentifier getInstance(
ASN1TaggedObject obj,
boolean explicit)
{
return getInstance(ASN1Sequence.getInstance(obj, explicit));
}
public static AlgorithmIdentifier getInstance(
Object obj)
{
if (obj instanceof AlgorithmIdentifier)
{
return (AlgorithmIdentifier)obj;
}
if (obj instanceof DERObjectIdentifier)
{
return new AlgorithmIdentifier((DERObjectIdentifier)obj);
}
if (obj instanceof String)
{
return new AlgorithmIdentifier((String)obj);
}
if (obj instanceof ASN1Sequence)
{
return new AlgorithmIdentifier((ASN1Sequence)obj);
}
throw new IllegalArgumentException("unknown object in factory");
}
public AlgorithmIdentifier(
DERObjectIdentifier objectId)
{
this.objectId = objectId;
}
public AlgorithmIdentifier(
String objectId)
{
this.objectId = new DERObjectIdentifier(objectId);
}
public AlgorithmIdentifier(
DERObjectIdentifier objectId,
DEREncodable parameters)
{
parametersDefined = true;
this.objectId = objectId;
this.parameters = parameters;
}
public AlgorithmIdentifier(
ASN1Sequence seq)
{
objectId = (DERObjectIdentifier)seq.getObjectAt(0);
if (seq.size() == 2)
{
parametersDefined = true;
parameters = seq.getObjectAt(1);
}
else
{
parameters = null;
}
}
public DERObjectIdentifier getObjectId()
{
return objectId;
}
public DEREncodable getParameters()
{
return parameters;
}
/**
* Produce an object suitable for an ASN1OutputStream.
* <pre>
* AlgorithmIdentifier ::= SEQUENCE {
* algorithm OBJECT IDENTIFIER,
* parameters ANY DEFINED BY algorithm OPTIONAL }
* </pre>
*/
public DERObject toASN1Object()
{
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(objectId);
if (parametersDefined)
{
v.add(parameters);
}
return new DERSequence(v);
}
}