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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [gnu/] [javax/] [net/] [ssl/] [provider/] [Finished.java] - Blame information for rev 769

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 769 jeremybenn
/* Finished.java -- SSL Finished message.
2
   Copyright (C) 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.net.ssl.provider;
40
 
41
import java.io.PrintWriter;
42
import java.io.StringWriter;
43
 
44
import java.nio.ByteBuffer;
45
 
46
final class Finished implements Handshake.Body
47
{
48
 
49
  // Fields.
50
  // -------------------------------------------------------------------------
51
 
52
  private final ByteBuffer buffer;
53
  private final ProtocolVersion version;
54
 
55
  // Constructor.
56
  // -------------------------------------------------------------------------
57
 
58
  Finished (final ByteBuffer buffer, final ProtocolVersion version)
59
  {
60
    buffer.getClass ();
61
    version.getClass ();
62
    this.buffer = buffer;
63
    this.version = version;
64
  }
65
 
66
  // Instance methods.
67
  // -------------------------------------------------------------------------
68
 
69
  public int length ()
70
  {
71
    if (version.compareTo(ProtocolVersion.TLS_1) >= 0)
72
      return 12;
73
    if (version == ProtocolVersion.SSL_3)
74
      return 36;
75
    throw new IllegalArgumentException ("length for this version unknown");
76
  }
77
 
78
  byte[] verifyData()
79
  {
80
    if (version.compareTo(ProtocolVersion.TLS_1) >= 0)
81
      {
82
        byte[] verify = new byte[12];
83
        buffer.position (0);
84
        buffer.get (verify);
85
        return verify;
86
      }
87
    throw new IllegalArgumentException ("not TLSv1.0 or later");
88
  }
89
 
90
  byte[] md5Hash()
91
  {
92
    if (version == ProtocolVersion.SSL_3)
93
      {
94
        byte[] md5 = new byte[16];
95
        buffer.position (0);
96
        buffer.get (md5);
97
        return md5;
98
      }
99
    throw new IllegalArgumentException ("not SSLv3");
100
  }
101
 
102
  byte[] shaHash()
103
  {
104
    if (version == ProtocolVersion.SSL_3)
105
      {
106
        byte[] sha = new byte[20];
107
        buffer.position (16);
108
        buffer.get (sha);
109
        return sha;
110
      }
111
    throw new IllegalArgumentException ("not SSLv3");
112
  }
113
 
114
  void setVerifyData (final byte[] verifyData, final int offset)
115
  {
116
    if (version == ProtocolVersion.SSL_3)
117
      throw new IllegalArgumentException ("not TLSv1");
118
    buffer.position (0);
119
    buffer.put (verifyData, offset, 12);
120
  }
121
 
122
  void setMD5Hash (final byte[] md5, final int offset)
123
  {
124
    if (version != ProtocolVersion.SSL_3)
125
      throw new IllegalArgumentException ("not SSLv3");
126
    buffer.position (0);
127
    buffer.put (md5, offset, 16);
128
  }
129
 
130
  void setShaHash (final byte[] sha, final int offset)
131
  {
132
    if (version != ProtocolVersion.SSL_3)
133
      throw new IllegalArgumentException ("not SSLv3");
134
    buffer.position (16);
135
    buffer.put (sha, offset, 20);
136
  }
137
 
138
  public String toString ()
139
  {
140
    return toString (null);
141
  }
142
 
143
  public String toString (final String prefix)
144
  {
145
    StringWriter str = new StringWriter ();
146
    PrintWriter out = new PrintWriter (str);
147
    if (prefix != null)
148
      out.print (prefix);
149
    out.println ("struct {");
150
    if (prefix != null)
151
      out.print (prefix);
152
    if (version.compareTo(ProtocolVersion.TLS_1) >= 0)
153
      {
154
        out.print ("  verifyData = ");
155
        out.print (Util.toHexString (verifyData (), ':'));
156
      }
157
    else if (version == ProtocolVersion.SSL_3)
158
      {
159
        out.print ("  md5 = ");
160
        out.print (Util.toHexString (md5Hash (), ':'));
161
        out.println (';');
162
        if (prefix != null)
163
          out.print (prefix);
164
        out.print ("  sha = ");
165
        out.print (Util.toHexString (shaHash (), ':'));
166
      }
167
    out.println (';');
168
    if (prefix != null)
169
      out.print (prefix);
170
    out.print ("} Finished;");
171
    return str.toString ();
172
  }
173
}

powered by: WebSVN 2.1.0

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