Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.security.jgss/share/classes/sun/security/krb5/internal/MethodData.java
41161 views
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
31
package sun.security.krb5.internal;
32
33
import sun.security.util.*;
34
import sun.security.krb5.Asn1Exception;
35
import java.io.IOException;
36
import java.math.BigInteger;
37
38
/**
39
* Implements the ASN.1 EncKrbPrivPart type.
40
*
41
* <pre>{@code
42
* METHOD-DATA ::= SEQUENCE {
43
* method-type[0] INTEGER,
44
* method-data[1] OCTET STRING OPTIONAL
45
* }
46
* }</pre>
47
*/
48
public class MethodData {
49
private int methodType;
50
private byte[] methodData = null; //optional
51
52
public MethodData(int type, byte[] data) {
53
methodType = type;
54
if (data != null) {
55
methodData = data.clone();
56
}
57
}
58
59
/**
60
* Constructs a MethodData object.
61
* @param encoding a Der-encoded data.
62
* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
63
* @exception IOException if an I/O error occurs while reading encoded data.
64
*/
65
public MethodData(DerValue encoding) throws Asn1Exception, IOException {
66
DerValue der;
67
if (encoding.getTag() != DerValue.tag_Sequence) {
68
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
69
}
70
der = encoding.getData().getDerValue();
71
if ((der.getTag() & 0x1F) == 0x00) {
72
BigInteger bint = der.getData().getBigInteger();
73
methodType = bint.intValue();
74
}
75
else
76
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
77
if (encoding.getData().available() > 0) {
78
der = encoding.getData().getDerValue();
79
if ((der.getTag() & 0x1F) == 0x01) {
80
methodData = der.getData().getOctetString();
81
}
82
else throw new Asn1Exception(Krb5.ASN1_BAD_ID);
83
}
84
if (encoding.getData().available() > 0)
85
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
86
}
87
88
/**
89
* Encodes an MethodData object.
90
* @return the byte array of encoded MethodData object.
91
* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
92
* @exception IOException if an I/O error occurs while reading encoded data.
93
*/
94
95
public byte[] asn1Encode() throws Asn1Exception, IOException {
96
DerOutputStream bytes = new DerOutputStream();
97
DerOutputStream temp = new DerOutputStream();
98
temp.putInteger(BigInteger.valueOf(methodType));
99
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x00), temp);
100
if (methodData != null) {
101
temp = new DerOutputStream();
102
temp.putOctetString(methodData);
103
bytes.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0x01), temp);
104
}
105
106
temp = new DerOutputStream();
107
temp.write(DerValue.tag_Sequence, bytes);
108
return temp.toByteArray();
109
}
110
111
}
112
113