OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [gnu/] [javax/] [crypto/] [jce/] [params/] [DERReader.java] - Blame information for rev 769

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* DERReader.java --
2
   Copyright (C) 1999, 2006  Free Software Foundation, Inc.
3
 
4
This file is a part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or (at
9
your option) any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19
USA
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
37
 
38
 
39
package gnu.javax.crypto.jce.params;
40
 
41
import java.math.BigInteger;
42
 
43
class DERReader
44
{
45
  byte source[];
46
  int pos;
47
  static final int UNIVERSAL = 1;
48
  static final int APPLICATION = 2;
49
  static final int CONTEXT_SPECIFIC = 3;
50
  static final int PRIVATE = 4;
51
 
52
  public DERReader()
53
  {
54
    source = null;
55
    pos = 0;
56
  }
57
 
58
  public DERReader(byte source[])
59
  {
60
    init(source);
61
  }
62
 
63
  public void init(String source)
64
  {
65
    init(source.getBytes());
66
  }
67
 
68
  public void init(byte source[])
69
  {
70
    this.source = source;
71
    pos = 0;
72
  }
73
 
74
  public boolean hasMorePrimitives()
75
  {
76
    return pos < source.length;
77
  }
78
 
79
  public BigInteger getBigInteger() throws DEREncodingException
80
  {
81
    return new BigInteger(getPrimitive());
82
  }
83
 
84
  // Reads Primitive, definite-length method
85
  private byte[] getPrimitive() throws DEREncodingException
86
  {
87
    int tmp = pos;
88
    // Read Identifier
89
    byte identifier = source[tmp++];
90
    if ((0x20 & identifier) != 0)
91
      throw new DEREncodingException();
92
    int type = translateLeadIdentifierByte(identifier);
93
    // get tag
94
    int tag = (0x1f & identifier);
95
    // get length
96
    byte len = source[tmp]; // may be length of length parameter
97
    long length = 0x7f & len;
98
    int i;
99
    if ((0x80 & len) != 0)
100
      {
101
        len &= 0x7f;
102
        // get length here
103
        length = 0;
104
        for (i = 0; i < len; i++)
105
          {
106
            tmp++;
107
            length <<= 8;
108
            length += (source[tmp] < 0) ? (256 + source[tmp]) : source[tmp];
109
          }
110
        tmp++;
111
      }
112
    else
113
      tmp++;
114
 
115
    byte tmpb[] = new byte[(int) length];
116
    System.arraycopy(source, tmp, tmpb, 0, (int) length);
117
    pos = (int) (tmp + length);
118
    return tmpb;
119
  }
120
 
121
  private int translateLeadIdentifierByte(byte b)
122
  {
123
    if ((0x3f & b) == b)
124
      return UNIVERSAL;
125
    else if ((0x7f & b) == b)
126
      return APPLICATION;
127
    else if ((0xbf & b) == b)
128
      return CONTEXT_SPECIFIC;
129
    else
130
      return PRIVATE;
131
  }
132
 
133
  private int getIdentifier(int tpos)
134
  {
135
    while ((0x80 & source[tpos]) != 0)
136
      tpos++;
137
    return tpos;
138
  }
139
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.