summary refs log tree commit diff
path: root/crypto/src/asn1/misc/CAST5CBCParameters.cs
blob: 7bd9f1ec6ee0c4ea8d01464ab4aab54c94102c88 (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
64
65
66
67
68
69
70
71
72
73
74
using System;

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Utilities;

namespace Org.BouncyCastle.Asn1.Misc
{
    public class Cast5CbcParameters
        : Asn1Encodable
    {
        private readonly DerInteger keyLength;
        private readonly Asn1OctetString iv;

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

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

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

		public Cast5CbcParameters(
            byte[]	iv,
            int		keyLength)
        {
            this.iv = new DerOctetString(iv);
            this.keyLength = new DerInteger(keyLength);
        }

		private Cast5CbcParameters(
            Asn1Sequence seq)
        {
			if (seq.Count != 2)
				throw new ArgumentException("Wrong number of elements in sequence", "seq");

			iv = (Asn1OctetString) seq[0];
            keyLength = (DerInteger) seq[1];
        }

		public byte[] GetIV()
        {
			return Arrays.Clone(iv.GetOctets());
		}

		public int KeyLength
		{
            get { return keyLength.IntValueExact; }
		}

		/**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         * cast5CBCParameters ::= Sequence {
         *                           iv         OCTET STRING DEFAULT 0,
         *                                  -- Initialization vector
         *                           keyLength  Integer
         *                                  -- Key length, in bits
         *                      }
         * </pre>
         */
        public override Asn1Object ToAsn1Object()
        {
			return new DerSequence(iv, keyLength);
        }
    }
}