source: trunk/gcc/libjava/gnu/gcj/io/SimpleSHSStream.java

Last change on this file was 2, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.3 KB
Line 
1// SimpleSHSStream.java
2
3/* Copyright (C) 2000 Free Software Foundation
4
5 This file is part of libgcj.
6
7This software is copyrighted work licensed under the terms of the
8Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9details. */
10
11package gnu.gcj.io;
12import java.io.Serializable;
13import java.io.*;
14import java.lang.reflect.*;
15
16public class SimpleSHSStream extends java.io.DataOutputStream
17{
18 int counter;
19
20 final int SHS_BLOCKSIZE = 64;
21 final int SHS_DIGESTSIZE = 20;
22
23 byte buf[];
24 byte shs_info[];
25
26 native static byte [] shsFinal (byte info[]);
27 native static void shsUpdate (byte info[], byte buf[], int count);
28 native static byte [] shsInit ();
29
30 private void update (byte b)
31 {
32 buf [counter++] = b;
33 if (counter % SHS_BLOCKSIZE == 0)
34 {
35 counter = 0;
36 shsUpdate (shs_info, buf, SHS_BLOCKSIZE);
37 }
38 }
39
40 public void write (int b) throws IOException
41 {
42 update ((byte)b);
43 super.write (b);
44 }
45
46 public void write (byte[] b, int off, int len) throws IOException
47 {
48 for (int i = 0; i < len; i++)
49 write (b[i+off]);
50 }
51
52 public byte[] digest()
53 {
54 shsUpdate (shs_info, buf, counter);
55 return shsFinal (shs_info);
56 }
57
58 public SimpleSHSStream (OutputStream out)
59 {
60 super (out);
61 buf = new byte[SHS_BLOCKSIZE];
62 shs_info = shsInit ();
63 counter = 0;
64 }
65}
66
Note: See TracBrowser for help on using the repository browser.