blob: ebd2261502b1f05abb0f4a97f1190cc10f160ee6 (
plain)
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
|
package org.bouncycastle.bcpg;
import java.io.*;
import java.math.BigInteger;
/**
* a multiple precision integer
*/
public class MPInteger
extends BCPGObject
{
BigInteger value = null;
public MPInteger(
BCPGInputStream in)
throws IOException
{
int length = (in.read() << 8) | in.read();
byte[] bytes = new byte[(length + 7) / 8];
in.readFully(bytes);
value = new BigInteger(1, bytes);
}
public MPInteger(
BigInteger value)
{
if (value == null || value.signum() < 0)
{
throw new IllegalArgumentException("value must not be null, or negative");
}
this.value = value;
}
public BigInteger getValue()
{
return value;
}
public void encode(
BCPGOutputStream out)
throws IOException
{
int length = value.bitLength();
out.write(length >> 8);
out.write(length);
byte[] bytes = value.toByteArray();
if (bytes[0] == 0)
{
out.write(bytes, 1, bytes.length - 1);
}
else
{
out.write(bytes, 0, bytes.length);
}
}
}
|