The Android Open Source Project | adc854b | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | * contributor license agreements. See the NOTICE file distributed with |
| 4 | * this work for additional information regarding copyright ownership. |
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | * (the "License"); you may not use this file except in compliance with |
| 7 | * the License. You may obtain a copy of the License at |
| 8 | * |
| 9 | * 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 | |
| 19 | package org.apache.harmony.security.provider.crypto; |
| 20 | |
| 21 | import org.apache.harmony.security.asn1.ASN1Integer; |
| 22 | import org.apache.harmony.security.asn1.ASN1Sequence; |
| 23 | import org.apache.harmony.security.asn1.ASN1Type; |
| 24 | import org.apache.harmony.security.asn1.BerInputStream; |
| 25 | |
| 26 | |
| 27 | /** |
| 28 | * The auxiliary class providing means to process ASN1Sequence of three Integers. |
Elliott Hughes | f33eae7 | 2010-05-13 12:36:25 -0700 | [diff] [blame] | 29 | * Such sequences are parts of ASN1 encoded formats for DSA private and public keys. |
The Android Open Source Project | adc854b | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 30 | */ |
| 31 | class ThreeIntegerSequence { |
| 32 | |
| 33 | byte[] p, q, g; |
| 34 | |
| 35 | private byte[] encoding; |
| 36 | |
| 37 | ThreeIntegerSequence(byte[] p, byte[] q, byte[] g) { |
| 38 | |
| 39 | this.p = p; |
| 40 | this.q = q; |
| 41 | this.g = g; |
| 42 | encoding = null; |
| 43 | } |
| 44 | |
| 45 | public byte[] getEncoded() { |
| 46 | if (encoding == null) { |
| 47 | encoding = ASN1.encode(this); |
| 48 | } |
| 49 | return encoding; |
| 50 | } |
| 51 | |
| 52 | public static final ASN1Sequence ASN1 = new ASN1Sequence(new ASN1Type[] { |
| 53 | ASN1Integer.getInstance(), ASN1Integer.getInstance(), |
| 54 | ASN1Integer.getInstance() }) { |
| 55 | |
| 56 | protected Object getDecodedObject(BerInputStream in) { |
| 57 | |
| 58 | Object[] values = (Object[]) in.content; |
| 59 | |
| 60 | return new ThreeIntegerSequence((byte[]) values[0], |
| 61 | (byte[]) values[1], (byte[]) values[2]); |
| 62 | } |
| 63 | |
| 64 | protected void getValues(Object object, Object[] values) { |
| 65 | |
| 66 | ThreeIntegerSequence mySeq = (ThreeIntegerSequence) object; |
| 67 | |
| 68 | values[0] = mySeq.p; |
| 69 | values[1] = mySeq.q; |
| 70 | values[2] = mySeq.g; |
| 71 | } |
| 72 | }; |
| 73 | } |