root/ext/digest/sha1.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ScmSha1
  2. sha1_allocate
  3. Scm_Init_sha1
  4. sha1__25sha1_update
  5. sha1__25sha1_final
  6. Scm_Init_sha1

   1 /* Generated by genstub.  Do not edit. */
   2 #include <gauche.h>
   3 #if defined(__CYGWIN__) || defined(__MINGW32__)
   4 #define SCM_CGEN_CONST /*empty*/
   5 #else
   6 #define SCM_CGEN_CONST const
   7 #endif
   8 
   9  #include <gauche/extend.h>
  10  #include <gauche/class.h>
  11  #include <gauche/uvector.h>
  12  #include "sha.h"
  13 
  14  typedef struct ScmSha1Rec {
  15    SCM_HEADER;
  16    SHA_CTX ctx;
  17  } ScmSha1;
  18 
  19  SCM_CLASS_DECL(Scm_Sha1Class);
  20  static ScmObj sha1_allocate(ScmClass *, ScmObj);
  21  SCM_DEFINE_BUILTIN_CLASS(Scm_Sha1Class,
  22                           NULL, NULL, NULL, sha1_allocate,
  23                           NULL);
  24 
  25  #define SCM_CLASS_SHA1      (&Scm_Sha1Class)
  26  #define SCM_SHA1(obj)       ((ScmSha1*)obj)
  27  #define SCM_SHA1P(obj)      SCM_XTYPEP(obj, SCM_CLASS_SHA1)
  28 
  29  static ScmObj sha1_allocate(ScmClass *klass, ScmObj initargs)
  30  {
  31    ScmSha1 *sha1 = SCM_ALLOCATE(ScmSha1, klass);
  32    SCM_SET_CLASS(sha1, klass);
  33    SHAInit(&sha1->ctx);
  34    return SCM_OBJ(sha1);
  35  }
  36 
  37  /* Hack for initialization stub */
  38  static void Scm_sha_internal_init(ScmModule*);
  39  void Scm_Init_sha1(void)
  40  {
  41    ScmModule *mod = SCM_FIND_MODULE("rfc.sha1", SCM_FIND_MODULE_CREATE);
  42    SCM_INIT_EXTENSION(sha1);
  43    Scm_InitStaticClass(&Scm_Sha1Class, "<sha1-context>", mod, NULL, 0);
  44    Scm_sha_internal_init(mod);
  45  }
  46 
  47  #define Scm_Init_sha1 Scm_sha_internal_init
  48 
  49 static ScmObj sha1__25sha1_update(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
  50 {
  51   ScmObj sha1_scm;
  52   ScmSha1* sha1;
  53   ScmObj data_scm;
  54   ScmObj data;
  55   SCM_ENTER_SUBR("%sha1-update");
  56   sha1_scm = SCM_ARGREF(0);
  57   if (!SCM_SHA1P(sha1_scm)) Scm_Error("<sha1> required, but got %S", sha1_scm);
  58   sha1 = SCM_SHA1(sha1_scm);
  59   data_scm = SCM_ARGREF(1);
  60   data = (data_scm);
  61   {
  62 
  63   if (SCM_U8VECTORP(data)) {
  64     SHAUpdate(&sha1->ctx, (const unsigned char*)SCM_UVECTOR_ELEMENTS(SCM_U8VECTOR(data)), SCM_U8VECTOR_SIZE(SCM_U8VECTOR(data)));
  65   } else if (SCM_STRINGP(data)) {
  66     const ScmStringBody *b = SCM_STRING_BODY(data);
  67     SHAUpdate(&sha1->ctx, 
  68               (const unsigned char*)SCM_STRING_BODY_START(b), 
  69               SCM_STRING_BODY_SIZE(b));
  70   } else {
  71     Scm_Error("u8vector or string required, but got: %S", data);
  72   }
  73   SCM_RETURN(SCM_UNDEFINED);
  74   }
  75 }
  76 
  77 static SCM_DEFINE_STRING_CONST(sha1__25sha1_update__NAME, "%sha1-update", 12, 12);
  78 static SCM_DEFINE_SUBR(sha1__25sha1_update__STUB, 2, 0, SCM_OBJ(&sha1__25sha1_update__NAME), sha1__25sha1_update, NULL, NULL);
  79 
  80 static ScmObj sha1__25sha1_final(ScmObj *SCM_FP, int SCM_ARGCNT, void *data_)
  81 {
  82   ScmObj sha1_scm;
  83   ScmSha1* sha1;
  84   SCM_ENTER_SUBR("%sha1-final");
  85   sha1_scm = SCM_ARGREF(0);
  86   if (!SCM_SHA1P(sha1_scm)) Scm_Error("<sha1> required, but got %S", sha1_scm);
  87   sha1 = SCM_SHA1(sha1_scm);
  88   {
  89   unsigned char digest[20];
  90   SHAFinal(digest, &sha1->ctx);
  91   SCM_RETURN(Scm_MakeString((const char*)digest, 20, 20, SCM_MAKSTR_INCOMPLETE|SCM_MAKSTR_COPYING));
  92   }
  93 }
  94 
  95 static SCM_DEFINE_STRING_CONST(sha1__25sha1_final__NAME, "%sha1-final", 11, 11);
  96 static SCM_DEFINE_SUBR(sha1__25sha1_final__STUB, 1, 0, SCM_OBJ(&sha1__25sha1_final__NAME), sha1__25sha1_final, NULL, NULL);
  97 
  98 void Scm_Init_sha1(ScmModule *module)
  99 {
 100 
 101   SCM_DEFINE(module, "%sha1-final", SCM_OBJ(&sha1__25sha1_final__STUB));
 102   SCM_DEFINE(module, "%sha1-update", SCM_OBJ(&sha1__25sha1_update__STUB));
 103 }

/* [<][>][^][v][top][bottom][index][help] */