// Path: src/org/jruby/ext/krypt/digest/RubyNativeDigest.java
// public class RubyNativeDigest extends RubyObject {
//     
//     private static RubyClass cNativeDigest;
//     
//     public RubyNativeDigest(Ruby runtime, Digest digest) {
//         super(runtime, cNativeDigest);
//         this.digest = digest;
//     }
//         
//     private Digest digest;
//     
//     @JRubyMethod
//     public IRubyObject reset(ThreadContext ctx) {
//         this.digest.reset();
//         return this;
//     }
//     
//     @JRubyMethod(name={"update","<<"})
//     public IRubyObject update(ThreadContext ctx, IRubyObject data) {
//         try {
//             byte[] bytes = data.asString().getBytes();
//             this.digest.update(bytes, 0, bytes.length);
//             return this;
//         } catch (Exception ex) {
//             throw Errors.newDigestError(ctx.getRuntime(), "Error while updating digest: " + ex.getMessage());
//         }
//     }
//     
//     @JRubyMethod(optional=1)
//     public IRubyObject digest(ThreadContext ctx, IRubyObject[] args) {
//         Ruby runtime = ctx.getRuntime();
//         if (args.length == 0)
//             return digestFinalize(runtime);
//         else
//             return digestData(runtime, args[0]);
//     }
//     
//     @JRubyMethod(optional=1)
//     public IRubyObject hexdigest(ThreadContext ctx, IRubyObject[] args) {
//         IRubyObject result = digest(ctx, args);
//         byte[] encoded = Hex.encode(result.asString().getBytes());
//         return RubyString.newUsAsciiStringNoCopy(ctx.getRuntime(), new ByteList(encoded, false));
//     }
//     
//     @JRubyMethod
//     public IRubyObject name(ThreadContext ctx) {
//         return ctx.getRuntime().newString(this.digest.getName());
//     }
//     
//     @JRubyMethod
//     public IRubyObject digest_length(ThreadContext ctx) {
//         return RubyNumeric.int2fix(ctx.getRuntime(), this.digest.getDigestLength());
//     }
//     
//     @JRubyMethod
//     public IRubyObject block_length(ThreadContext ctx) {
//         return RubyNumeric.int2fix(ctx.getRuntime(), this.digest.getBlockLength());
//     }
//     
//     private IRubyObject digestFinalize(Ruby runtime) {
//         try {
//             byte[] result = digest.digest();
//             return runtime.newString(new ByteList(result, false));
//         } catch (Exception ex) {
//             throw Errors.newDigestError(runtime, "Error while finalizing digest: " + ex.getMessage());
//         }
//     }
//     
//     private IRubyObject digestData(Ruby runtime, IRubyObject rbdata) {
//         try {
//             byte[] data = rbdata.asString().getBytes();
//             byte[] result = digest.digest(data);
//             return runtime.newString(new ByteList(result, false));
//         } catch (Exception ex) {
//             throw Errors.newDigestError(runtime, "Error while computing digest: " + ex.getMessage());
//         }
//     }
//     
//     public static void createDigest(Ruby runtime, RubyModule krypt) {
//         RubyModule mDigest = (RubyModule)krypt.getConstant("Digest");
//         cNativeDigest = mDigest.defineClassUnder("NativeDigest", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
//         cNativeDigest.defineAnnotatedMethods(RubyNativeDigest.class);
//     }
// }


import org.jruby.RubyObject;
import org.jruby.anno.JRubyMethod;
import org.jruby.ext.krypt.digest.RubyNativeDigest;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyModule;
    }
    
    @JRubyMethod(required = 1, rest = true)
    public IRubyObject new_service(ThreadContext ctx, IRubyObject[] args) {
        IRubyObject serviceClass = args[0];
        
        if (serviceClass == mDigest) {
            return newDigest(ctx, stripFirst(args));
        }
        
        return ctx.getRuntime().getNil();
    }
    
    @JRubyMethod
    public IRubyObject finalize(ThreadContext ctx) {
        /* do nothing */
        provider.cleanUp();
        return ctx.getRuntime().getNil();
    }
    
    private IRubyObject newDigest(ThreadContext ctx, IRubyObject[] args) {
        Ruby runtime = ctx.getRuntime();
        if (args == null) return runtime.getNil();
        String nameOrOid = args[0].convertToString().asJavaString();
        Digest digest = provider.newDigestByName(nameOrOid);
        if (digest == null)
            digest = provider.newDigestByOid(nameOrOid);
        if (digest == null)
            return runtime.getNil();
        else
// Path: src/org/jruby/ext/krypt/digest/RubyNativeDigest.java
// public class RubyNativeDigest extends RubyObject {
//     
//     private static RubyClass cNativeDigest;
//     
//     public RubyNativeDigest(Ruby runtime, Digest digest) {
//         super(runtime, cNativeDigest);
//         this.digest = digest;
//     }
//         
//     private Digest digest;
//     
//     @JRubyMethod
//     public IRubyObject reset(ThreadContext ctx) {
//         this.digest.reset();
//         return this;
//     }
//     
//     @JRubyMethod(name={"update","<<"})
//     public IRubyObject update(ThreadContext ctx, IRubyObject data) {
//         try {
//             byte[] bytes = data.asString().getBytes();
//             this.digest.update(bytes, 0, bytes.length);
//             return this;
//         } catch (Exception ex) {
//             throw Errors.newDigestError(ctx.getRuntime(), "Error while updating digest: " + ex.getMessage());
//         }
//     }
//     
//     @JRubyMethod(optional=1)
//     public IRubyObject digest(ThreadContext ctx, IRubyObject[] args) {
//         Ruby runtime = ctx.getRuntime();
//         if (args.length == 0)
//             return digestFinalize(runtime);
//         else
//             return digestData(runtime, args[0]);
//     }
//     
//     @JRubyMethod(optional=1)
//     public IRubyObject hexdigest(ThreadContext ctx, IRubyObject[] args) {
//         IRubyObject result = digest(ctx, args);
//         byte[] encoded = Hex.encode(result.asString().getBytes());
//         return RubyString.newUsAsciiStringNoCopy(ctx.getRuntime(), new ByteList(encoded, false));
//     }
//     
//     @JRubyMethod
//     public IRubyObject name(ThreadContext ctx) {
//         return ctx.getRuntime().newString(this.digest.getName());
//     }
//     
//     @JRubyMethod
//     public IRubyObject digest_length(ThreadContext ctx) {
//         return RubyNumeric.int2fix(ctx.getRuntime(), this.digest.getDigestLength());
//     }
//     
//     @JRubyMethod
//     public IRubyObject block_length(ThreadContext ctx) {
//         return RubyNumeric.int2fix(ctx.getRuntime(), this.digest.getBlockLength());
//     }
//     
//     private IRubyObject digestFinalize(Ruby runtime) {
//         try {
//             byte[] result = digest.digest();
//             return runtime.newString(new ByteList(result, false));
//         } catch (Exception ex) {
//             throw Errors.newDigestError(runtime, "Error while finalizing digest: " + ex.getMessage());
//         }
//     }
//     
//     private IRubyObject digestData(Ruby runtime, IRubyObject rbdata) {
//         try {
//             byte[] data = rbdata.asString().getBytes();
//             byte[] result = digest.digest(data);
//             return runtime.newString(new ByteList(result, false));
//         } catch (Exception ex) {
//             throw Errors.newDigestError(runtime, "Error while computing digest: " + ex.getMessage());
//         }
//     }
//     
//     public static void createDigest(Ruby runtime, RubyModule krypt) {
//         RubyModule mDigest = (RubyModule)krypt.getConstant("Digest");
//         cNativeDigest = mDigest.defineClassUnder("NativeDigest", runtime.getObject(), ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
//         cNativeDigest.defineAnnotatedMethods(RubyNativeDigest.class);
//     }
// }


// Path: src/org/jruby/ext/krypt/provider/RubyNativeProvider.java
import org.jruby.RubyObject;
import org.jruby.anno.JRubyMethod;
import org.jruby.ext.krypt.digest.RubyNativeDigest;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyModule;

    }
    
    @JRubyMethod(required = 1, rest = true)
    public IRubyObject new_service(ThreadContext ctx, IRubyObject[] args) {
        IRubyObject serviceClass = args[0];
        
        if (serviceClass == mDigest) {
            return newDigest(ctx, stripFirst(args));
        }
        
        return ctx.getRuntime().getNil();
    }
    
    @JRubyMethod
    public IRubyObject finalize(ThreadContext ctx) {
        /* do nothing */
        provider.cleanUp();
        return ctx.getRuntime().getNil();
    }
    
    private IRubyObject newDigest(ThreadContext ctx, IRubyObject[] args) {
        Ruby runtime = ctx.getRuntime();
        if (args == null) return runtime.getNil();
        String nameOrOid = args[0].convertToString().asJavaString();
        Digest digest = provider.newDigestByName(nameOrOid);
        if (digest == null)
            digest = provider.newDigestByOid(nameOrOid);
        if (digest == null)
            return runtime.getNil();
        else
            return new RubyNativeDigest(runtime, digest);