src/share/classes/sun/security/pkcs11/P11Key.java
Print this page
7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -879,11 +879,34 @@
public String toString() {
fetchValues();
return super.toString() + "\n x: " + x + "\n p: " + params.getP()
+ "\n g: " + params.getG();
}
+ public int hashCode() {
+ if (token.isValid() == false) {
+ return 0;
}
+ fetchValues();
+ return Objects.hash(x, params.getP(), params.getG());
+ }
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ // equals() should never throw exceptions
+ if (token.isValid() == false) {
+ return false;
+ }
+ if (!(obj instanceof DHPrivateKey)) {
+ return false;
+ }
+ fetchValues();
+ DHPrivateKey other = (DHPrivateKey) obj;
+ DHParameterSpec otherParams = other.getParams();
+ return ((this.x.compareTo(other.getX()) == 0) &&
+ (this.params.getP().compareTo(otherParams.getP()) == 0) &&
+ (this.params.getG().compareTo(otherParams.getG()) == 0));
+ }
+ }
private static final class P11DHPublicKey extends P11Key
implements DHPublicKey {
static final long serialVersionUID = -598383872153843657L;
@@ -943,11 +966,34 @@
public String toString() {
fetchValues();
return super.toString() + "\n y: " + y + "\n p: " + params.getP()
+ "\n g: " + params.getG();
}
+ public int hashCode() {
+ if (token.isValid() == false) {
+ return 0;
}
+ fetchValues();
+ return Objects.hash(y, params.getP(), params.getG());
+ }
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ // equals() should never throw exceptions
+ if (token.isValid() == false) {
+ return false;
+ }
+ if (!(obj instanceof DHPublicKey)) {
+ return false;
+ }
+ fetchValues();
+ DHPublicKey other = (DHPublicKey) obj;
+ DHParameterSpec otherParams = other.getParams();
+ return ((this.y.compareTo(other.getY()) == 0) &&
+ (this.params.getP().compareTo(otherParams.getP()) == 0) &&
+ (this.params.getG().compareTo(otherParams.getG()) == 0));
+ }
+ }
private static final class P11ECPrivateKey extends P11Key
implements ECPrivateKey {
private static final long serialVersionUID = -7786054399510515515L;