author | igerasim |
Tue, 02 Oct 2018 10:19:07 -0700 | |
changeset 51986 | c1db377f6300 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1997, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package sun.security.x509; |
|
26 |
||
27 |
import java.io.IOException; |
|
28 |
import java.math.BigInteger; |
|
29 |
||
34687
d302ed125dc9
8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents:
30374
diff
changeset
|
30 |
import sun.security.util.HexDumpEncoder; |
2 | 31 |
import sun.security.util.*; |
32 |
||
33 |
/** |
|
34 |
* This class defines the UniqueIdentity class used by certificates. |
|
35 |
* |
|
36 |
* @author Amit Kapoor |
|
37 |
* @author Hemma Prafullchandra |
|
38 |
*/ |
|
39 |
public class UniqueIdentity { |
|
40 |
// Private data members |
|
41 |
private BitArray id; |
|
42 |
||
43 |
/** |
|
44 |
* The default constructor for this class. |
|
45 |
* |
|
46 |
* @param id the byte array containing the unique identifier. |
|
47 |
*/ |
|
48 |
public UniqueIdentity(BitArray id) { |
|
49 |
this.id = id; |
|
50 |
} |
|
51 |
||
52 |
/** |
|
53 |
* The default constructor for this class. |
|
54 |
* |
|
55 |
* @param id the byte array containing the unique identifier. |
|
56 |
*/ |
|
57 |
public UniqueIdentity(byte[] id) { |
|
58 |
this.id = new BitArray(id.length*8, id); |
|
59 |
} |
|
60 |
||
61 |
/** |
|
62 |
* Create the object, decoding the values from the passed DER stream. |
|
63 |
* |
|
64 |
* @param in the DerInputStream to read the UniqueIdentity from. |
|
65 |
* @exception IOException on decoding errors. |
|
66 |
*/ |
|
67 |
public UniqueIdentity(DerInputStream in) throws IOException { |
|
68 |
DerValue derVal = in.getDerValue(); |
|
69 |
id = derVal.getUnalignedBitString(true); |
|
70 |
} |
|
71 |
||
72 |
/** |
|
73 |
* Create the object, decoding the values from the passed DER stream. |
|
74 |
* |
|
75 |
* @param derVal the DerValue decoded from the stream. |
|
76 |
* @exception IOException on decoding errors. |
|
77 |
*/ |
|
78 |
public UniqueIdentity(DerValue derVal) throws IOException { |
|
79 |
id = derVal.getUnalignedBitString(true); |
|
80 |
} |
|
81 |
||
82 |
/** |
|
83 |
* Return the UniqueIdentity as a printable string. |
|
84 |
*/ |
|
85 |
public String toString() { |
|
86 |
return ("UniqueIdentity:" + id.toString() + "\n"); |
|
87 |
} |
|
88 |
||
89 |
/** |
|
90 |
* Encode the UniqueIdentity in DER form to the stream. |
|
91 |
* |
|
92 |
* @param out the DerOutputStream to marshal the contents to. |
|
93 |
* @param tag enocode it under the following tag. |
|
94 |
* @exception IOException on errors. |
|
95 |
*/ |
|
96 |
public void encode(DerOutputStream out, byte tag) throws IOException { |
|
97 |
byte[] bytes = id.toByteArray(); |
|
98 |
int excessBits = bytes.length*8 - id.length(); |
|
99 |
||
100 |
out.write(tag); |
|
101 |
out.putLength(bytes.length + 1); |
|
102 |
||
103 |
out.write(excessBits); |
|
104 |
out.write(bytes); |
|
105 |
} |
|
106 |
||
107 |
/** |
|
108 |
* Return the unique id. |
|
109 |
*/ |
|
110 |
public boolean[] getId() { |
|
111 |
if (id == null) return null; |
|
112 |
||
113 |
return id.toBooleanArray(); |
|
114 |
} |
|
115 |
} |