Skip to content

Commit 37c988c

Browse files
committed
implement PKey initialize_copy (dup-ing)
1 parent ba7cb83 commit 37c988c

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/main/java/org/jruby/ext/openssl/PKeyDH.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ public PKeyDH(Ruby runtime, RubyClass clazz) {
110110
super(runtime, clazz);
111111
}
112112

113+
@Override
114+
public IRubyObject initialize_copy(final IRubyObject original) {
115+
if (this == original) return this;
116+
checkFrozen();
117+
118+
final PKeyDH that = (PKeyDH) original;
119+
this.dh_p = that.dh_p;
120+
this.dh_g = that.dh_g;
121+
this.dh_y = that.dh_y;
122+
this.dh_x = that.dh_x;
123+
return this;
124+
}
125+
113126
@JRubyMethod(name="initialize", rest=true, visibility = Visibility.PRIVATE)
114127
public synchronized IRubyObject initialize(final ThreadContext context, final IRubyObject[] args) {
115128
final Ruby runtime = context.runtime;

src/main/java/org/jruby/ext/openssl/PKeyDSA.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ public PKeyDSA(Ruby runtime, RubyClass type, DSAPrivateKey privKey, DSAPublicKey
113113
private transient volatile BigInteger dsa_q;
114114
private transient volatile BigInteger dsa_g;
115115

116+
@Override
117+
public IRubyObject initialize_copy(final IRubyObject original) {
118+
if (this == original) return this;
119+
checkFrozen();
120+
121+
final PKeyDSA that = (PKeyDSA) original;
122+
this.publicKey = that.publicKey;
123+
this.privateKey = that.privateKey;
124+
this.dsa_x = that.dsa_x;
125+
this.dsa_y = that.dsa_y;
126+
this.dsa_p = that.dsa_p;
127+
this.dsa_q = that.dsa_q;
128+
this.dsa_g = that.dsa_g;
129+
return this;
130+
}
131+
116132
@Override
117133
public PublicKey getPublicKey() { return publicKey; }
118134

src/main/java/org/jruby/ext/openssl/PKeyRSA.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,25 @@ public PKeyRSA(Ruby runtime, RubyClass type, RSAPrivateCrtKey privKey, RSAPublic
141141
private transient volatile BigInteger rsa_dmq1;
142142
private transient volatile BigInteger rsa_iqmp;
143143

144+
@Override
145+
public IRubyObject initialize_copy(final IRubyObject original) {
146+
if (this == original) return this;
147+
checkFrozen();
148+
149+
final PKeyRSA that = (PKeyRSA) original;
150+
this.publicKey = that.publicKey;
151+
this.privateKey = that.privateKey;
152+
this.rsa_e = that.rsa_e;
153+
this.rsa_n = that.rsa_n;
154+
this.rsa_d = that.rsa_d;
155+
this.rsa_p = that.rsa_p;
156+
this.rsa_q = that.rsa_q;
157+
this.rsa_dmp1 = that.rsa_dmp1;
158+
this.rsa_dmq1 = that.rsa_dmq1;
159+
this.rsa_iqmp = that.rsa_iqmp;
160+
return this;
161+
}
162+
144163
@Override
145164
public PublicKey getPublicKey() { return publicKey; }
146165

0 commit comments

Comments
 (0)