crypto_hash.cc 913 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * Node Native Module for Lib Sodium
  3. *
  4. * @Author Pedro Paixao
  5. * @email paixaop at gmail dot com
  6. * @License MIT
  7. */
  8. #include "node_sodium.h"
  9. /**
  10. * int crypto_hash(
  11. * unsigned char * hbuf,
  12. * const unsigned char * msg,
  13. * unsigned long long mlen)
  14. */
  15. NAN_METHOD(bind_crypto_hash) {
  16. Nan::EscapableHandleScope scope;
  17. NUMBER_OF_MANDATORY_ARGS(1,"argument message must be a buffer");
  18. GET_ARG_AS_UCHAR(0,msg);
  19. NEW_BUFFER_AND_PTR(hash, crypto_hash_BYTES);
  20. if( crypto_hash(hash_ptr, msg, msg_size) == 0 ) {
  21. return info.GetReturnValue().Set(hash);
  22. } else {
  23. return JS_NULL;
  24. }
  25. }
  26. /**
  27. * Register function calls in node binding
  28. */
  29. void register_crypto_hash(Handle<Object> target) {
  30. // Hash
  31. NEW_METHOD(crypto_hash);
  32. NEW_INT_PROP(crypto_hash_BYTES);
  33. //NEW_INT_PROP(crypto_hash_BLOCKBYTES);
  34. NEW_STRING_PROP(crypto_hash_PRIMITIVE);
  35. }