[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: awt fixes

Kaffe CVS cvs-commits at kaffe.org
Thu May 19 03:22:16 PDT 2005


PatchSet 6556 
Date: 2005/05/19 10:18:01
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: awt fixes

2005-05-19  Dalibor Topic  <robilad at kaffe.org>

        Resynced with GNU Classpath.

        2005-05-18  Thomas Fitzsimmons  <fitzsim at redhat.com>

        * java/awt/Window.java (createBufferStrategy): Remove unnecessary
        try-catch blocks.
        * java/awt/Canvas.java (createBufferStrategy): Likewise.

        * gnu/java/security/provider/DSASignature.java: Import updates
        from GNU Crypto.

Members: 
	ChangeLog:1.4082->1.4083 
	libraries/javalib/gnu/java/security/provider/DSASignature.java:1.2->1.3 
	libraries/javalib/java/awt/Canvas.java:1.19->1.20 
	libraries/javalib/java/awt/Window.java:1.33->1.34 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4082 kaffe/ChangeLog:1.4083
--- kaffe/ChangeLog:1.4082	Thu May 19 09:29:49 2005
+++ kaffe/ChangeLog	Thu May 19 10:18:01 2005
@@ -1,5 +1,18 @@
 2005-05-19  Dalibor Topic  <robilad at kaffe.org>
 
+        Resynced with GNU Classpath.
+
+	2005-05-18  Thomas Fitzsimmons  <fitzsim at redhat.com>
+
+        * java/awt/Window.java (createBufferStrategy): Remove unnecessary
+        try-catch blocks.
+        * java/awt/Canvas.java (createBufferStrategy): Likewise.
+
+        * gnu/java/security/provider/DSASignature.java: Import updates
+        from GNU Crypto.
+
+2005-05-19  Dalibor Topic  <robilad at kaffe.org>
+
 	* Makefile.am (EXTRA_DIST): removed libtool patches.
 
 	* FAQ/FAQ.automake: Updated.
Index: kaffe/libraries/javalib/gnu/java/security/provider/DSASignature.java
diff -u kaffe/libraries/javalib/gnu/java/security/provider/DSASignature.java:1.2 kaffe/libraries/javalib/gnu/java/security/provider/DSASignature.java:1.3
--- kaffe/libraries/javalib/gnu/java/security/provider/DSASignature.java:1.2	Fri Oct 15 10:41:46 2004
+++ kaffe/libraries/javalib/gnu/java/security/provider/DSASignature.java	Thu May 19 10:18:04 2005
@@ -7,7 +7,7 @@
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2, or (at your option)
 any later version.
- 
+
 GNU Classpath is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
@@ -51,7 +51,6 @@
 import java.security.InvalidParameterException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
 import java.security.PrivateKey;
 import java.security.PublicKey;
 import java.security.SecureRandom;
@@ -67,54 +66,49 @@
 {
   private DSAPublicKey publicKey;
   private DSAPrivateKey privateKey;
-  private MessageDigest digest = null;
+  private final MessageDigest digest;
+  private final SecureRandom random;
 
-  public DSASignature()
-  {}
+  public DSASignature() throws NoSuchAlgorithmException
+  {
+    random = new SecureRandom();
+    digest = MessageDigest.getInstance ("SHA1");
+  }
 
   private void init()
   {
-    if( digest == null ) {
-      try {
-	digest = MessageDigest.getInstance( "SHA1", "GNU" );
-      } catch ( NoSuchAlgorithmException nsae ) {
-	digest = null;
-      } catch ( NoSuchProviderException nspe ) {
-	digest = null;
-      }
-    }
     digest.reset();
   }
 
-  public void engineInitVerify(PublicKey publicKey)
+  public void engineInitVerify (PublicKey publicKey)
     throws InvalidKeyException
   {
-    if( publicKey instanceof DSAPublicKey )
-      this.publicKey = (DSAPublicKey)publicKey;
+    if (publicKey instanceof DSAPublicKey)
+      this.publicKey = (DSAPublicKey) publicKey;
     else
       throw new InvalidKeyException();
     init();
   }
 
-  public void engineInitSign(PrivateKey privateKey)
+  public void engineInitSign (PrivateKey privateKey)
     throws InvalidKeyException
   {
-    if( privateKey instanceof DSAPrivateKey )
-      this.privateKey = (DSAPrivateKey)privateKey;
+    if (privateKey instanceof DSAPrivateKey)
+      this.privateKey = (DSAPrivateKey) privateKey;
     else
-      throw new InvalidKeyException();
+      throw new InvalidKeyException ("not a DSA private key");
 
     init();
   }
 
-  public void engineInitSign(PrivateKey privateKey, 
-			     SecureRandom random)
+  public void engineInitSign (PrivateKey privateKey,
+                              SecureRandom random)
     throws InvalidKeyException
   {
-    if( privateKey instanceof DSAPrivateKey )
-      this.privateKey = (DSAPrivateKey)privateKey;
+    if (privateKey instanceof DSAPrivateKey)
+      this.privateKey = (DSAPrivateKey) privateKey;
     else
-      throw new InvalidKeyException();
+      throw new InvalidKeyException ("not a DSA private key");
 
     appRandom = random;
     init();
@@ -123,141 +117,135 @@
   public void engineUpdate(byte b)
     throws SignatureException
   {
-    if( digest == null )
-      throw new SignatureException();		
-
-    digest.update( b );
+    digest.update (b);
   }
 
-  public void engineUpdate(byte[] b, int off, int len)
+  public void engineUpdate (byte[] b, int off, int len)
     throws SignatureException
   {
-    if( digest == null )
-      throw new SignatureException();		
-
-    digest.update( b, off, len );
+    digest.update (b, off, len);
   }
 
-  public byte[] engineSign()
-    throws SignatureException
+  public byte[] engineSign() throws SignatureException
   {
-    if( digest == null )
-      throw new SignatureException();		
-    if( privateKey == null)
-      throw new SignatureException();		
+    if (privateKey == null)
+      throw new SignatureException ("not initialized for signing");
 
-    try {
+    try
+      {
+        BigInteger g = privateKey.getParams().getG();
+        BigInteger p = privateKey.getParams().getP();
+        BigInteger q = privateKey.getParams().getQ();
 
-      BigInteger g = privateKey.getParams().getG();
-      BigInteger p = privateKey.getParams().getP();
-      BigInteger q = privateKey.getParams().getQ();
+        BigInteger x = privateKey.getX();
 
-      BigInteger x = privateKey.getX();
+        BigInteger k = new BigInteger (159, appRandom != null ? appRandom : random);
 
-      BigInteger k = new BigInteger( 159, (Random)appRandom );
+        BigInteger r = g.modPow(k, p);
+        r = r.mod(q);
 
-      BigInteger r = g.modPow(k, p);
-      r = r.mod(q);
+        byte bytes[] = digest.digest();
+        BigInteger sha = new BigInteger (1, bytes);
 
-      byte bytes[] = digest.digest();
-      BigInteger sha = new BigInteger(1, bytes);
+        BigInteger s = sha.add (x.multiply (r));
+        s = s.multiply (k.modInverse(q)).mod (q);
 
-      BigInteger s = sha.add( x.multiply( r ) );
-      s = s.multiply( k.modInverse(q) ).mod( q );
-
-      ByteArrayOutputStream bout = new ByteArrayOutputStream();
-      ArrayList seq = new ArrayList(2);
-      seq.set(0, new DERValue(DER.INTEGER, r));
-      seq.set(1, new DERValue(DER.INTEGER, s));
-      DERWriter.write(bout, new DERValue(DER.CONSTRUCTED | DER.SEQUENCE, seq));
-      return bout.toByteArray();
-    } catch (IOException ioe) {
-      throw new SignatureException();
-    } catch ( ArithmeticException ae ) {
-      throw new SignatureException();
-    }
+        ByteArrayOutputStream bout = new ByteArrayOutputStream();
+        ArrayList seq = new ArrayList (2);
+        seq.add(0, new DERValue (DER.INTEGER, r));
+        seq.add(1, new DERValue (DER.INTEGER, s));
+        DERWriter.write (bout, new DERValue (DER.CONSTRUCTED | DER.SEQUENCE, seq));
+        return bout.toByteArray();
+      }
+    catch (IOException ioe)
+      {
+        SignatureException se = new SignatureException();
+        se.initCause (ioe);
+        throw se;
+      }
+    catch (ArithmeticException ae)
+      {
+        SignatureException se = new SignatureException();
+        se.initCause (ae);
+        throw se;
+      }
   }
 
-  public int engineSign(byte[] outbuf, int offset, int len)
+  public int engineSign (byte[] outbuf, int offset, int len)
     throws SignatureException
   {
     byte tmp[] = engineSign();
-    if( tmp.length > len )
-      throw new SignatureException();
-    System.arraycopy( tmp, 0, outbuf, offset, tmp.length );
+    if (tmp.length > len)
+      throw new SignatureException ("output buffer too short");
+    System.arraycopy (tmp, 0, outbuf, offset, tmp.length);
     return tmp.length;
   }
 
-  public boolean engineVerify(byte[] sigBytes)
+  public boolean engineVerify (byte[] sigBytes)
     throws SignatureException
   {
-    //Decode sigBytes from ASN.1 DER encoding
-    try {
-      DERReader in = new DERReader(sigBytes);
-      DERValue val = in.read();
-      if (!val.isConstructed())
-        throw new SignatureException("badly formed signature");
-      BigInteger r = (BigInteger) in.read().getValue();
-      BigInteger s = (BigInteger) in.read().getValue();
+    // Decode sigBytes from ASN.1 DER encoding
+    try
+      {
+        DERReader in = new DERReader (sigBytes);
+        DERValue val = in.read();
+        if (!val.isConstructed())
+          throw new SignatureException ("badly formed signature");
+        BigInteger r = (BigInteger) in.read().getValue();
+        BigInteger s = (BigInteger) in.read().getValue();
 
-      BigInteger g = publicKey.getParams().getG();
-      BigInteger p = publicKey.getParams().getP();
-      BigInteger q = publicKey.getParams().getQ();
+        BigInteger g = publicKey.getParams().getG();
+        BigInteger p = publicKey.getParams().getP();
+        BigInteger q = publicKey.getParams().getQ();
 
-      BigInteger y = publicKey.getY();
+        BigInteger y = publicKey.getY();
 
-      BigInteger w = s.modInverse( q );
+        BigInteger w = s.modInverse (q);
 
-      byte bytes[] = digest.digest();
-      BigInteger sha = new BigInteger(1, bytes);
+        byte bytes[] = digest.digest();
+        BigInteger sha = new BigInteger (1, bytes);
 
-      BigInteger u1 = w.multiply( sha ).mod( q );
+        BigInteger u1 = w.multiply (sha).mod ( q );
 
-      BigInteger u2 = r.multiply( w ).mod( q );
+        BigInteger u2 = r.multiply (w).mod(q);
 
-      //This should test the compiler :)
-      BigInteger v = g.modPow( u1, p ).multiply( y.modPow( u2, p ) ).mod( p ).mod( q );
+        BigInteger v = g.modPow (u1, p).multiply (y.modPow (u2, p)).mod (p).mod (q);
 
-      if( v.equals( r ) )
-	return true;
-      else
-	return false;
-    } catch (IOException ioe) {
-      throw new SignatureException("badly formed signature");
-    }
+        if (v.equals (r))
+          return true;
+        else
+          return false;
+      }
+    catch (IOException ioe)
+      {
+        SignatureException se = new SignatureException ("badly formed signature");
+        se.initCause (ioe);
+        throw se;
+      }
   }
 
-  public void engineSetParameter(String param,
-				 Object value)
+  public void engineSetParameter (String param,
+                                  Object value)
     throws InvalidParameterException
   {
     throw new InvalidParameterException();
   }
 
-  public void engineSetParameter(AlgorithmParameterSpec params)
+  public void engineSetParameter (AlgorithmParameterSpec params)
     throws InvalidAlgorithmParameterException
   {
     throw new InvalidParameterException();
 
   }
 
-  public Object engineGetParameter(String param)
+  public Object engineGetParameter (String param)
     throws InvalidParameterException
   {
     throw new InvalidParameterException();
   }
 
-  public Object clone()
-    //throws CloneNotSupportedException
-  {
-    return new DSASignature( this );
-  }
-
-  private DSASignature( DSASignature copy )
+  public Object clone() throws CloneNotSupportedException
   {
-    this();
-    this.publicKey = copy.publicKey;
-    this.privateKey = copy.privateKey;
-    this.digest = copy.digest;
+    return super.clone();
   }
 }
Index: kaffe/libraries/javalib/java/awt/Canvas.java
diff -u kaffe/libraries/javalib/java/awt/Canvas.java:1.19 kaffe/libraries/javalib/java/awt/Canvas.java:1.20
--- kaffe/libraries/javalib/java/awt/Canvas.java:1.19	Thu May 19 00:31:17 2005
+++ kaffe/libraries/javalib/java/awt/Canvas.java	Thu May 19 10:18:05 2005
@@ -255,21 +255,22 @@
       throw new IllegalStateException("Canvas.createBufferStrategy: canvas is"
 				      + " not displayable");
 
+    BufferStrategy newStrategy = null;
+
     // try a flipping strategy
     try
       {
-	bufferStrategy = new CanvasFlipBufferStrategy(numBuffers);
-	return;
+	newStrategy = new CanvasFlipBufferStrategy(numBuffers);
       }
     catch (AWTException e)
       {
       }
 
-    // try an accelerated blitting strategy
-    bufferStrategy = new CanvasBltBufferStrategy(numBuffers, true);
+    // fall back to an accelerated blitting strategy
+    if (newStrategy == null)
+      newStrategy = new CanvasBltBufferStrategy(numBuffers, true);
 
-    // fall back to an unaccelerated blitting strategy
-    bufferStrategy = new CanvasBltBufferStrategy(numBuffers, false);
+    bufferStrategy = newStrategy;
   }
 
   /**
Index: kaffe/libraries/javalib/java/awt/Window.java
diff -u kaffe/libraries/javalib/java/awt/Window.java:1.33 kaffe/libraries/javalib/java/awt/Window.java:1.34
--- kaffe/libraries/javalib/java/awt/Window.java:1.33	Thu May 19 00:31:18 2005
+++ kaffe/libraries/javalib/java/awt/Window.java	Thu May 19 10:18:05 2005
@@ -878,21 +878,22 @@
       throw new IllegalStateException("Window.createBufferStrategy: window is"
 				      + " not displayable");
 
+    BufferStrategy newStrategy = null;
+
     // try a flipping strategy
     try
       {
-	bufferStrategy = new WindowFlipBufferStrategy(numBuffers);
-	return;
+	newStrategy = new WindowFlipBufferStrategy(numBuffers);
       }
     catch (AWTException e)
       {
       }
 
-    // try an accelerated blitting strategy
-    bufferStrategy = new WindowBltBufferStrategy(numBuffers, true);
+    // fall back to an accelerated blitting strategy
+    if (newStrategy == null)
+      newStrategy = new WindowBltBufferStrategy(numBuffers, true);
 
-    // fall back to an unaccelerated blitting strategy
-    bufferStrategy = new WindowBltBufferStrategy(numBuffers, false);
+    bufferStrategy = newStrategy;
   }
 
   /**




More information about the kaffe mailing list