Skip to content

Commit

Permalink
JRUBY-4754: NotImplementedError: the MD5() function is unimplemented …
Browse files Browse the repository at this point in the history
…on this machine
  • Loading branch information
enebo committed Apr 26, 2010
1 parent 9e1d154 commit c31f184
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/org/jruby/RubyDigest.java
Expand Up @@ -405,16 +405,30 @@ public DigestBase(Ruby runtime, RubyClass type) {
if(type == runtime.fastGetModule("Digest").fastGetClass("Base")) {
throw runtime.newNotImplementedError("Digest::Base is an abstract class");
}
if(!type.hasInternalVariable("metadata")) {

Metadata metadata = getMetadata(type);
if(metadata == null) {
throw runtime.newNotImplementedError("the " + type + "() function is unimplemented on this machine");
}

try {
setAlgorithm((Metadata)type.getInternalVariable("metadata"));
setAlgorithm(metadata);
} catch(NoSuchAlgorithmException e) {
throw runtime.newNotImplementedError("the " + type + "() function is unimplemented on this machine");
}

}

// if subclass extends particular digest we need to walk to find it...we should rearchitect digest to avoid walking type systems
private Metadata getMetadata(RubyModule type) {
for (RubyModule current = type; current != null; current = current.getSuperClass()) {
Metadata metadata = (Metadata) current.getInternalVariable("metadata");

if (metadata != null) return metadata;
}

return null;
}

@JRubyMethod(optional = 1, frame = true)
public IRubyObject initialize(IRubyObject[] args, Block unusedBlock) {
Expand Down

0 comments on commit c31f184

Please sign in to comment.