aboutsummaryrefslogtreecommitdiff
path: root/libphobos/testsuite/libphobos.phobos/std_digest_ripemd.d
blob: 582a21bd7219abe6a25369fb9db55c144c8ed825 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
@safe unittest
{
    import std.digest.ripemd;

    //Template API
    import std.digest.md;

    ubyte[20] hash = ripemd160Of("abc");
    assert(toHexString(hash) == "8EB208F7E05D987A9B044A8E98C6B087F15A0BFC");

    //Feeding data
    ubyte[1024] data;
    RIPEMD160 md;
    md.start();
    md.put(data[]);
    md.start(); //Start again
    md.put(data[]);
    hash = md.finish();
}

@safe unittest
{
    import std.digest.ripemd;

    //OOP API
    import std.digest.md;

    auto md = new RIPEMD160Digest();
    ubyte[] hash = md.digest("abc");
    assert(toHexString(hash) == "8EB208F7E05D987A9B044A8E98C6B087F15A0BFC");

    //Feeding data
    ubyte[1024] data;
    md.put(data[]);
    md.reset(); //Start again
    md.put(data[]);
    hash = md.finish();
}

@safe unittest
{
    import std.digest.ripemd;

    //Simple example, hashing a string using ripemd160Of helper function
    ubyte[20] hash = ripemd160Of("abc");
    //Let's get a hash string
    assert(toHexString(hash) == "8EB208F7E05D987A9B044A8E98C6B087F15A0BFC");
}

@safe unittest
{
    import std.digest.ripemd;

    //Using the basic API
    RIPEMD160 hash;
    hash.start();
    ubyte[1024] data;
    //Initialize data here...
    hash.put(data);
    ubyte[20] result = hash.finish();
}

@safe unittest
{
    import std.digest.ripemd;

    //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);
    assert(toHexString(md.finish()) == "C81B94933420221A7AC004A90242D8B1D3E5070D");
}

@safe unittest
{
    import std.digest.ripemd;

    //Simple example
    RIPEMD160 hash;
    hash.start();
    hash.put(cast(ubyte) 0);
    ubyte[20] result = hash.finish();
    assert(toHexString(result) == "C81B94933420221A7AC004A90242D8B1D3E5070D");
}

@safe unittest
{
    import std.digest.ripemd;

    ubyte[20] hash = ripemd160Of("abc");
    assert(hash == digest!RIPEMD160("abc"));
}

@safe unittest
{
    import std.digest.ripemd;

    //Simple example, hashing a string using Digest.digest helper function
    auto md = new RIPEMD160Digest();
    ubyte[] hash = md.digest("abc");
    //Let's get a hash string
    assert(toHexString(hash) == "8EB208F7E05D987A9B044A8E98C6B087F15A0BFC");
}

@system unittest
{
    import std.digest.ripemd;

    //Let's use the OOP features:
    void test(Digest dig)
    {
      dig.put(cast(ubyte) 0);
    }
    auto md = new RIPEMD160Digest();
    test(md);

    //Let's use a custom buffer:
    ubyte[20] buf;
    ubyte[] result = md.finish(buf[]);
    assert(toHexString(result) == "C81B94933420221A7AC004A90242D8B1D3E5070D");
}