jdk/src/share/classes/sun/security/pkcs11/P11Key.java
changeset 18809 97f5713a0f1a
parent 17491 7a33824ec8c5
child 18813 02de3cfa6c49
equal deleted inserted replaced
18808:b2eaaaaed037 18809:97f5713a0f1a
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   879         public String toString() {
   879         public String toString() {
   880             fetchValues();
   880             fetchValues();
   881             return super.toString() +  "\n  x: " + x + "\n  p: " + params.getP()
   881             return super.toString() +  "\n  x: " + x + "\n  p: " + params.getP()
   882                 + "\n  g: " + params.getG();
   882                 + "\n  g: " + params.getG();
   883         }
   883         }
       
   884         public int hashCode() {
       
   885             if (token.isValid() == false) {
       
   886                 return 0;
       
   887             }
       
   888             fetchValues();
       
   889             return Objects.hash(x, params.getP(), params.getG());
       
   890         }
       
   891         public boolean equals(Object obj) {
       
   892             if (this == obj) return true;
       
   893             // equals() should never throw exceptions
       
   894             if (token.isValid() == false) {
       
   895                 return false;
       
   896             }
       
   897             if (!(obj instanceof DHPrivateKey)) {
       
   898                 return false;
       
   899             }
       
   900             fetchValues();
       
   901             DHPrivateKey other = (DHPrivateKey) obj;
       
   902             DHParameterSpec otherParams = other.getParams();
       
   903             return ((this.x.compareTo(other.getX()) == 0) &&
       
   904                     (this.params.getP().compareTo(otherParams.getP()) == 0) &&
       
   905                     (this.params.getG().compareTo(otherParams.getG()) == 0));
       
   906         }
   884     }
   907     }
   885 
   908 
   886     private static final class P11DHPublicKey extends P11Key
   909     private static final class P11DHPublicKey extends P11Key
   887                                                 implements DHPublicKey {
   910                                                 implements DHPublicKey {
   888         static final long serialVersionUID = -598383872153843657L;
   911         static final long serialVersionUID = -598383872153843657L;
   942         }
   965         }
   943         public String toString() {
   966         public String toString() {
   944             fetchValues();
   967             fetchValues();
   945             return super.toString() +  "\n  y: " + y + "\n  p: " + params.getP()
   968             return super.toString() +  "\n  y: " + y + "\n  p: " + params.getP()
   946                 + "\n  g: " + params.getG();
   969                 + "\n  g: " + params.getG();
       
   970         }
       
   971         public int hashCode() {
       
   972             if (token.isValid() == false) {
       
   973                 return 0;
       
   974             }
       
   975             fetchValues();
       
   976             return Objects.hash(y, params.getP(), params.getG());
       
   977         }
       
   978         public boolean equals(Object obj) {
       
   979             if (this == obj) return true;
       
   980             // equals() should never throw exceptions
       
   981             if (token.isValid() == false) {
       
   982                 return false;
       
   983             }
       
   984             if (!(obj instanceof DHPublicKey)) {
       
   985                 return false;
       
   986             }
       
   987             fetchValues();
       
   988             DHPublicKey other = (DHPublicKey) obj;
       
   989             DHParameterSpec otherParams = other.getParams();
       
   990             return ((this.y.compareTo(other.getY()) == 0) &&
       
   991                     (this.params.getP().compareTo(otherParams.getP()) == 0) &&
       
   992                     (this.params.getG().compareTo(otherParams.getG()) == 0));
   947         }
   993         }
   948     }
   994     }
   949 
   995 
   950     private static final class P11ECPrivateKey extends P11Key
   996     private static final class P11ECPrivateKey extends P11Key
   951                                                 implements ECPrivateKey {
   997                                                 implements ECPrivateKey {