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/TransitedEncoding.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/security/krb5/internal/TransitedEncoding.java+136−0
@@ -0,0 +1,136 @@
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 *
27 * (C) Copyright IBM Corp. 1999 All Rights Reserved.
28 * Copyright 1997 The Open Group Research Institute. All rights reserved.
29 */
30
31package sun.security.krb5.internal;
32
33import sun.security.util.*;
34import sun.security.krb5.Asn1Exception;
35import java.io.IOException;
36import java.math.BigInteger;
37
38/**
39 * Implements the ASN.1 TransitedEncoding type.
40 *
41 * <xmp>
42 * TransitedEncoding ::= SEQUENCE {
43 * tr-type [0] Int32 -- must be registered --,
44 * contents [1] OCTET STRING
45 * }
46 * </xmp>
47 *
48 * <p>
49 * This definition reflects the Network Working Group RFC 4120
50 * specification available at
51 * <a href="http://www.ietf.org/rfc/rfc4120.txt">
52 * http://www.ietf.org/rfc/rfc4120.txt</a>.
53 */
54
55public class TransitedEncoding {
56 public int trType;
57 public byte[] contents;
58
59 public TransitedEncoding(int type, byte[] cont) {
60 trType = type;
61 contents = cont;
62 }
63
64 /**
65 * Constructs a TransitedEncoding object.
66 * @param encoding a Der-encoded data.
67 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
68 * @exception IOException if an I/O error occurs while reading encoded data.
69 */
70
71 public TransitedEncoding(DerValue encoding) throws Asn1Exception, IOException {
72 if (encoding.getTag() != DerValue.tag_Sequence) {
73 throw new Asn1Exception(Krb5.ASN1_BAD_ID);
74 }
75 DerValue der;
76 der = encoding.getData().getDerValue();
77 if ((der.getTag() & 0x1F) == 0x00) {
78 trType = der.getData().getBigInteger().intValue();
79 }
80 else
81 throw new Asn1Exception(Krb5.ASN1_BAD_ID);
82 der = encoding.getData().getDerValue();
83
84 if ((der.getTag() & 0x1F) == 0x01) {
85 contents = der.getData().getOctetString();
86 }
87 else
88 throw new Asn1Exception(Krb5.ASN1_BAD_ID);
89 if (der.getData().available() > 0)
90 throw new Asn1Exception(Krb5.ASN1_BAD_ID);
91 }
92
93 /**
94 * Encodes a TransitedEncoding object.
95 * @return the byte array of the encoded TransitedEncoding object.
96 * @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
97 * @exception IOException if an I/O error occurs while reading encoded data.
98 */
99 public byte[] asn1Encode() throws Asn1Exception, IOException {
100 DerOutputStream bytes = new DerOutputStream();
101 DerOutputStream temp = new DerOutputStream();
102 temp.putInteger(BigInteger.valueOf(trType));
103 bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
104 temp = new DerOutputStream();
105 temp.putOctetString(contents);
106 bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
107 temp = new DerOutputStream();
108 temp.write(DerValue.tag_Sequence, bytes);
109 return temp.toByteArray();
110 }
111
112 /**
113 * Parse (unmarshal) a TransitedEncoding object from a DER input stream. This form
114 * parsing might be used when expanding a value which is part of
115 * a constructed sequence and uses explicitly tagged type.
116 *
117 * @exception Asn1Exception on error.
118 * @param data the Der input stream value, which contains one or more marshaled value.
119 * @param explicitTag tag number.
120 * @param optional indicate if this data field is optional
121 * @return an instance of TransitedEncoding.
122 *
123 */
124 public static TransitedEncoding parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException {
125 if ((optional) && (((byte)data.peekByte() & (byte)0x1F) != explicitTag))
126 return null;
127 DerValue der = data.getDerValue();
128 if (explicitTag != (der.getTag() & (byte)0x1F)) {
129 throw new Asn1Exception(Krb5.ASN1_BAD_ID);
130 }
131 else {
132 DerValue subDer = der.getData().getDerValue();
133 return new TransitedEncoding(subDer);
134 }
135 }
136}