summaryrefslogtreecommitdiff
path: root/vere/pkg/noun/jets/e/ripe.c
blob: 5d08a9d2516ed3d09b58e188fe7f2e2291732d76 (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
/// @file

#include "jets/q.h"
#include "jets/w.h"

#include "noun.h"
#include "urcrypt.h"

  static u3_atom
  _cqe_ripe(u3_atom wid, u3_atom dat)
  {
    c3_w len_w;
    if ( !u3r_word_fit(&len_w, wid) ) {
      return u3m_bail(c3__fail);
    }
    else {
      u3_atom ret;
      c3_y out_y[20];
      c3_y *dat_y = u3r_bytes_alloc(0, len_w, dat);

      ret = ( 0 == urcrypt_ripemd160(dat_y, len_w, out_y) )
          ? u3i_bytes(20, out_y)
          : u3_none;

      u3a_free(dat_y);
      return ret;
    }
  }

  u3_noun
  u3we_ripe(u3_noun cor)
  {
    u3_noun wid, dat;

    if ( (c3n == u3r_mean(cor, u3x_sam_2, &wid,
                               u3x_sam_3, &dat, 0) ||
                 u3ud(wid) || u3ud(dat))
       )
    {
      return u3m_bail(c3__exit);
    }
    else {
      return u3l_punt("ripe", _cqe_ripe(wid, dat));
    }
  }