01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.auth.internal.kerberos.v5;
19:
20: import java.io.IOException;
21:
22: import org.apache.harmony.security.asn1.ASN1Explicit;
23: import org.apache.harmony.security.asn1.ASN1Integer;
24: import org.apache.harmony.security.asn1.ASN1OctetString;
25: import org.apache.harmony.security.asn1.ASN1Sequence;
26: import org.apache.harmony.security.asn1.ASN1Type;
27: import org.apache.harmony.security.asn1.BerInputStream;
28:
29: /**
30: * Kerberos EncryptionKey type.
31: *
32: * @see http://www.ietf.org/rfc/rfc4120.txt
33: */
34: public class EncryptionKey {
35:
36: private final int type;
37:
38: private final byte[] value;
39:
40: /**
41: * Creates EncryptionKey
42: *
43: * @param type -
44: * encryption type
45: * @param value -
46: * key value
47: */
48: public EncryptionKey(int type, byte[] value) {
49: this .type = type;
50: this .value = value;
51: }
52:
53: public int getType() {
54: return type;
55: }
56:
57: public byte[] getValue() {
58: return value;
59: }
60:
61: /**
62: * ASN.1 decoder for EncryptionKey
63: *
64: * EncryptionKey ::= SEQUENCE {
65: * keytype [0] Int32 -- actually encryption type --,
66: * keyvalue [1] OCTET STRING
67: * }
68: */
69: public static final ASN1Sequence ASN1 = new ASN1Sequence(
70: new ASN1Type[] {
71: // TODO should we define Int32 type?
72: new ASN1Explicit(0, ASN1Integer.getInstance()), // keytype
73: new ASN1Explicit(1, ASN1OctetString.getInstance()), // keyvalue
74: }) {
75:
76: @Override
77: protected Object getDecodedObject(BerInputStream in)
78: throws IOException {
79:
80: Object[] values = (Object[]) in.content;
81:
82: return new EncryptionKey(ASN1Integer.toIntValue(values[0]),
83: (byte[]) values[1]);
84: }
85:
86: @Override
87: protected void getValues(Object object, Object[] values) {
88:
89: EncryptionKey ekey = (EncryptionKey) object;
90:
91: values[0] = ASN1Integer.fromIntValue(ekey.type);
92: values[1] = ekey.value;
93: }
94: };
95: }
|