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.security.provider.crypto;
19:
20: import org.apache.harmony.security.asn1.ASN1Integer;
21: import org.apache.harmony.security.asn1.ASN1Sequence;
22: import org.apache.harmony.security.asn1.ASN1Type;
23: import org.apache.harmony.security.asn1.BerInputStream;
24:
25: /**
26: * The auxiliary class providing means to process ASN1Sequence of three Integers.
27: * Such sequences are parts of ASN1 encoded formats for DSA private and public keys.
28: */
29: class ThreeIntegerSequence {
30:
31: byte[] p, q, g;
32:
33: private byte[] encoding;
34:
35: ThreeIntegerSequence(byte[] p, byte[] q, byte[] g) {
36:
37: this .p = p;
38: this .q = q;
39: this .g = g;
40: encoding = null;
41: }
42:
43: public byte[] getEncoded() {
44: if (encoding == null) {
45: encoding = ASN1.encode(this );
46: }
47: return encoding;
48: }
49:
50: public static final ASN1Sequence ASN1 = new ASN1Sequence(
51: new ASN1Type[] { ASN1Integer.getInstance(),
52: ASN1Integer.getInstance(),
53: ASN1Integer.getInstance() }) {
54:
55: protected Object getDecodedObject(BerInputStream in) {
56:
57: Object[] values = (Object[]) in.content;
58:
59: return new ThreeIntegerSequence((byte[]) values[0],
60: (byte[]) values[1], (byte[]) values[2]);
61: }
62:
63: protected void getValues(Object object, Object[] values) {
64:
65: ThreeIntegerSequence mySeq = (ThreeIntegerSequence) object;
66:
67: values[0] = mySeq.p;
68: values[1] = mySeq.q;
69: values[2] = mySeq.g;
70: }
71: };
72: }
|