History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/security/krb5/internal/AuthorizationDataEntry.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/security/krb5/internal/AuthorizationDataEntry.java+124−0
@@ -0,0 +1,124 @@
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * This code is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 only, as
6 * published by the Free Software Foundation. Oracle designates this
7 * particular file as subject to the "Classpath" exception as provided
8 * by Oracle in the LICENSE file that accompanied this code.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25/*
26 * (C) Copyright IBM Corp. 1999 All Rights Reserved.
27 * Copyright 1997 The Open Group Research Institute. All rights reserved.
28 */
29
30package sun.security.krb5.internal;
31
32import sun.security.util.*;
33import java.io.IOException;
34import sun.security.krb5.Asn1Exception;
35import sun.security.krb5.internal.ccache.CCacheOutputStream;
36
37public class AuthorizationDataEntry implements Cloneable {
38
39 public int adType;
40 public byte[] adData;
41
42 private AuthorizationDataEntry() {
43 }
44
45 public AuthorizationDataEntry(
46 int new_adType,
47 byte[] new_adData) {
48 adType = new_adType;
49 adData = new_adData;
50 }
51
52 public Object clone() {
53 AuthorizationDataEntry new_authorizationDataEntry =
54 new AuthorizationDataEntry();
55 new_authorizationDataEntry.adType = adType;
56 if (adData != null) {
57 new_authorizationDataEntry.adData = new byte[adData.length];
58 System.arraycopy(adData, 0,
59 new_authorizationDataEntry.adData, 0, adData.length);
60 }
61 return new_authorizationDataEntry;
62 }
63
64 /**
65 * Constructs an instance of AuthorizationDataEntry.
66 * @param encoding a single DER-encoded value.
67 */
68 public AuthorizationDataEntry(DerValue encoding) throws Asn1Exception, IOException {
69 DerValue der;
70 if (encoding.getTag() != DerValue.tag_Sequence) {
71 throw new Asn1Exception(Krb5.ASN1_BAD_ID);
72 }
73 der = encoding.getData().getDerValue();
74 if ((der.getTag() & (byte) 0x1F) == (byte) 0x00) {
75 adType = der.getData().getBigInteger().intValue();
76 } else {
77 throw new Asn1Exception(Krb5.ASN1_BAD_ID);
78 }
79 der = encoding.getData().getDerValue();
80 if ((der.getTag() & (byte) 0x1F) == (byte) 0x01) {
81 adData = der.getData().getOctetString();
82 } else {
83 throw new Asn1Exception(Krb5.ASN1_BAD_ID);
84 }
85 if (encoding.getData().available() > 0) {
86 throw new Asn1Exception(Krb5.ASN1_BAD_ID);
87 }
88 }
89
90 /**
91 * Encodes an AuthorizationDataEntry object.
92 * @return byte array of encoded AuthorizationDataEntry object.
93 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
94 * @exception IOException if an I/O error occurs while reading encoded data.
95 */
96 public byte[] asn1Encode() throws Asn1Exception, IOException {
97 DerOutputStream bytes = new DerOutputStream();
98 DerOutputStream temp = new DerOutputStream();
99 temp.putInteger(adType);
100 bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x00), temp);
101 temp = new DerOutputStream();
102 temp.putOctetString(adData);
103 bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0x01), temp);
104 temp = new DerOutputStream();
105 temp.write(DerValue.tag_Sequence, bytes);
106 return temp.toByteArray();
107 }
108
109 /**
110 * Writes the entry's data fields in FCC format to an output stream.
111 *
112 * @param cos a <code>CCacheOutputStream</code>.
113 * @exception IOException if an I/O exception occurs.
114 */
115 public void writeEntry(CCacheOutputStream cos) throws IOException {
116 cos.write16(adType);
117 cos.write32(adData.length);
118 cos.write(adData, 0, adData.length);
119 }
120
121 public String toString() {
122 return ("adType=" + adType + " adData.length=" + adData.length);
123 }
124}