| Category | Functions |
|---|---|
| Template API | RIPEMD160 |
| OOP API | RIPEMD160Digest |
| Helpers | ripemd160Of |
CTFEDigests do not work in CTFE
Sourcestd/digest/ripemd.d
//Template APIimport std.digest.md;ubyte[20] hash = ripemd160Of("abc");writeln(toHexString(hash));// "8EB208F7E05D987A9B044A8E98C6B087F15A0BFC"//Feeding dataubyte[1024] data;RIPEMD160 md;md.start();md.put(data[]);md.start();//Start againmd.put(data[]);hash = md.finish();
//OOP APIimport std.digest.md;auto md =new RIPEMD160Digest();ubyte[] hash = md.digest("abc");writeln(toHexString(hash));// "8EB208F7E05D987A9B044A8E98C6B087F15A0BFC"//Feeding dataubyte[1024] data;md.put(data[]);md.reset();//Start againmd.put(data[]);hash = md.finish();
RIPEMD160;//Simple example, hashing a string using ripemd160Of helper functionubyte[20] hash = ripemd160Of("abc");//Let's get a hash stringwriteln(toHexString(hash));// "8EB208F7E05D987A9B044A8E98C6B087F15A0BFC"
//Using the basic APIRIPEMD160 hash;hash.start();ubyte[1024] data;//Initialize data here...hash.put(data);ubyte[20] result = hash.finish();
//Let's use the template features:void doSomething(T)(ref T hash)if (isDigest!T){ hash.put(cast(ubyte) 0);}RIPEMD160 md;md.start();doSomething(md);writeln(toHexString(md.finish()));// "C81B94933420221A7AC004A90242D8B1D3E5070D"
//Simple exampleRIPEMD160 hash;hash.start();hash.put(cast(ubyte) 0);ubyte[20] result = hash.finish();writeln(toHexString(result));// "C81B94933420221A7AC004A90242D8B1D3E5070D"
put(scope const(ubyte)[]data...);Example
RIPEMD160 dig;dig.put(cast(ubyte) 0);//single ubytedig.put(cast(ubyte) 0,cast(ubyte) 0);//variadicubyte[10] buf;dig.put(buf);//buffer
start();NoteFor this RIPEMD160 Digest implementation calling start after default construction is not necessary. Calling start is only necessary to reset the Digest.
Generic code which deals with different Digest types should always call start though.Example
RIPEMD160 digest;//digest.start(); //Not necessarydigest.put(0);finish();Example
//Simple exampleRIPEMD160 hash;hash.start();hash.put(cast(ubyte) 0);ubyte[20] result = hash.finish();assert(toHexString(result) =="C81B94933420221A7AC004A90242D8B1D3E5070D");
ripemd160Of(T...)(Tdata);ubyte[20] hash =ripemd160Of("abc");writeln(hash);// digest!RIPEMD160("abc")
RIPEMD160Digest = std.digest.WrapperDigest!(RIPEMD160).WrapperDigest;//Simple example, hashing a string using Digest.digest helper functionauto md =newRIPEMD160Digest();ubyte[] hash = md.digest("abc");//Let's get a hash stringwriteln(toHexString(hash));// "8EB208F7E05D987A9B044A8E98C6B087F15A0BFC"
//Let's use the OOP features:void test(Digest dig){ dig.put(cast(ubyte) 0);}auto md =newRIPEMD160Digest();test(md);//Let's use a custom buffer:ubyte[20] buf;ubyte[] result = md.finish(buf[]);writeln(toHexString(result));// "C81B94933420221A7AC004A90242D8B1D3E5070D"