2002/03/21 01:19:32
[org.ibex.core.git] / src / org / bouncycastle / asn1 / DERInteger.java
1 package org.bouncycastle.asn1;
2
3 import java.io.*;
4 import java.math.BigInteger;
5
6 public class DERInteger
7     extends DERObject
8 {
9     byte[]      bytes;
10
11     public DERInteger(
12         int         value)
13     {
14         bytes = BigInteger.valueOf(value).toByteArray();
15     }
16
17     public DERInteger(
18         BigInteger   value)
19     {
20         bytes = value.toByteArray();
21     }
22
23     public DERInteger(
24         byte[]   bytes)
25     {
26         this.bytes = bytes;
27     }
28
29     public BigInteger getValue()
30     {
31         return new BigInteger(bytes);
32     }
33
34     /**
35      * in some cases positive values get crammed into a space,
36      * that's not quite big enough...
37      */
38     public BigInteger getPositiveValue()
39     {
40         return new BigInteger(1, bytes);
41     }
42
43     void encode(
44         DEROutputStream out)
45         throws IOException
46     {
47         out.writeEncoded(INTEGER, bytes);
48     }
49 }