001package org.apache.commons.ssl.org.bouncycastle.asn1.cryptopro; 002 003import java.util.Enumeration; 004 005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector; 006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object; 007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1ObjectIdentifier; 008import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1OctetString; 009import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive; 010import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence; 011import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1TaggedObject; 012import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence; 013 014/** 015 * ASN.1 algorithm identifier parameters for GOST-28147 016 */ 017public class GOST28147Parameters 018 extends ASN1Object 019{ 020 private ASN1OctetString iv; 021 private ASN1ObjectIdentifier paramSet; 022 023 public static GOST28147Parameters getInstance( 024 ASN1TaggedObject obj, 025 boolean explicit) 026 { 027 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 028 } 029 030 public static GOST28147Parameters getInstance( 031 Object obj) 032 { 033 if (obj instanceof GOST28147Parameters) 034 { 035 return (GOST28147Parameters)obj; 036 } 037 038 if (obj != null) 039 { 040 return new GOST28147Parameters(ASN1Sequence.getInstance(obj)); 041 } 042 043 return null; 044 } 045 046 /** 047 * @deprecated use the getInstance() method. This constructor will vanish! 048 */ 049 public GOST28147Parameters( 050 ASN1Sequence seq) 051 { 052 Enumeration e = seq.getObjects(); 053 054 iv = (ASN1OctetString)e.nextElement(); 055 paramSet = (ASN1ObjectIdentifier)e.nextElement(); 056 } 057 058 /** 059 * <pre> 060 * Gost28147-89-Parameters ::= 061 * SEQUENCE { 062 * iv Gost28147-89-IV, 063 * encryptionParamSet OBJECT IDENTIFIER 064 * } 065 * 066 * Gost28147-89-IV ::= OCTET STRING (SIZE (8)) 067 * </pre> 068 */ 069 public ASN1Primitive toASN1Primitive() 070 { 071 ASN1EncodableVector v = new ASN1EncodableVector(); 072 073 v.add(iv); 074 v.add(paramSet); 075 076 return new DERSequence(v); 077 } 078 079 /** 080 * Return the OID representing the sBox to use. 081 * 082 * @return the sBox OID. 083 */ 084 public ASN1ObjectIdentifier getEncryptionParamSet() 085 { 086 return paramSet; 087 } 088 089 /** 090 * Return the initialisation vector to use. 091 * 092 * @return the IV. 093 */ 094 public byte[] getIV() 095 { 096 return iv.getOctets(); 097 } 098}