summary refs log tree commit diff
path: root/crypto/src/asn1/misc/IDEACBCPar.cs
blob: 96bfb89b02750e34d7f0cd54fb5ecc052c674a24 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;

using Org.BouncyCastle.Asn1;

namespace Org.BouncyCastle.Asn1.Misc
{
    public class IdeaCbcPar
        : Asn1Encodable
    {
        internal Asn1OctetString iv;

		public static IdeaCbcPar GetInstance(
            object o)
        {
            if (o is IdeaCbcPar)
            {
                return (IdeaCbcPar) o;
            }

			if (o is Asn1Sequence)
            {
                return new IdeaCbcPar((Asn1Sequence) o);
            }

			throw new ArgumentException("unknown object in IDEACBCPar factory");
        }

		public IdeaCbcPar(
            byte[] iv)
        {
            this.iv = new DerOctetString(iv);
        }

		private IdeaCbcPar(
            Asn1Sequence seq)
        {
			if (seq.Count == 1)
			{
				iv = (Asn1OctetString) seq[0];
			}
        }

		public byte[] GetIV()
        {
			return iv == null ? null : iv.GetOctets();
        }

		/**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         * IDEA-CBCPar ::= Sequence {
         *                      iv    OCTET STRING OPTIONAL -- exactly 8 octets
         *                  }
         * </pre>
         */
        public override Asn1Object ToAsn1Object()
        {
            return iv != null
                ?   new DerSequence(iv)
                :   DerSequence.Empty;
        }
    }
}