[ 
https://issues.apache.org/jira/browse/TS-4491?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15308142#comment-15308142
 ] 

ASF GitHub Bot commented on TS-4491:
------------------------------------

Github user jpeach commented on a diff in the pull request:

    https://github.com/apache/trafficserver/pull/681#discussion_r65223795
  
    --- Diff: plugins/experimental/ts_lua/ts_lua_crypto.c ---
    @@ -198,6 +222,130 @@ ts_lua_sha1_bin(lua_State *L)
     }
     
     static int
    +ts_lua_sha256(lua_State *L)
    +{
    +  u_char *src;
    +  size_t slen;
    +
    +  SHA256_CTX sha;
    +  u_char sha_buf[TS_LUA_SHA256_DIGEST_LENGTH];
    +  u_char hex_buf[2 * sizeof(sha_buf)];
    +
    +  if (lua_gettop(L) != 1) {
    +    return luaL_error(L, "expecting one argument");
    +  }
    +
    +  if (lua_isnil(L, 1)) {
    +    src = (u_char *)"";
    +    slen = 0;
    +
    +  } else {
    +    src = (u_char *)luaL_checklstring(L, 1, &slen);
    +  }
    +
    +  SHA256_Init(&sha);
    +  SHA256_Update(&sha, src, slen);
    +  SHA256_Final(sha_buf, &sha);
    +
    +  ts_lua_hex_dump(hex_buf, sha_buf, sizeof(sha_buf));
    +  lua_pushlstring(L, (char *)hex_buf, sizeof(hex_buf));
    +
    +  return 1;
    +}
    +
    +static int
    +ts_lua_sha256_bin(lua_State *L)
    +{
    +  u_char *src;
    +  size_t slen;
    +
    +  SHA256_CTX sha;
    +  u_char sha_buf[TS_LUA_SHA256_DIGEST_LENGTH];
    +
    +  if (lua_gettop(L) != 1) {
    +    return luaL_error(L, "expecting one argument");
    +  }
    +
    +  if (lua_isnil(L, 1)) {
    +    src = (u_char *)"";
    +    slen = 0;
    +
    +  } else {
    +    src = (u_char *)luaL_checklstring(L, 1, &slen);
    +  }
    +
    +  SHA256_Init(&sha);
    +  SHA256_Update(&sha, src, slen);
    +  SHA256_Final(sha_buf, &sha);
    +
    +  lua_pushlstring(L, (char *)sha_buf, sizeof(sha_buf));
    +
    +  return 1;
    +}
    +
    +static int
    +ts_lua_sha512(lua_State *L)
    +{
    +  u_char *src;
    +  size_t slen;
    +
    +  SHA512_CTX sha;
    +  u_char sha_buf[TS_LUA_SHA512_DIGEST_LENGTH];
    +  u_char hex_buf[2 * sizeof(sha_buf)];
    +
    +  if (lua_gettop(L) != 1) {
    +    return luaL_error(L, "expecting one argument");
    +  }
    +
    +  if (lua_isnil(L, 1)) {
    +    src = (u_char *)"";
    +    slen = 0;
    +
    +  } else {
    +    src = (u_char *)luaL_checklstring(L, 1, &slen);
    +  }
    +
    +  SHA512_Init(&sha);
    +  SHA512_Update(&sha, src, slen);
    +  SHA512_Final(sha_buf, &sha);
    +
    +  ts_lua_hex_dump(hex_buf, sha_buf, sizeof(sha_buf));
    +  lua_pushlstring(L, (char *)hex_buf, sizeof(hex_buf));
    +
    +  return 1;
    +}
    +
    +static int
    +ts_lua_sha512_bin(lua_State *L)
    --- End diff --
    
    Rather than duplicating all these hashing APIs, can we pass flags to a 
common implementation?


> support sha256/sha512 in ts_lua plugin
> --------------------------------------
>
>                 Key: TS-4491
>                 URL: https://issues.apache.org/jira/browse/TS-4491
>             Project: Traffic Server
>          Issue Type: Improvement
>          Components: Lua, Plugins
>            Reporter: Kit Chan
>            Assignee: Kit Chan
>             Fix For: 7.0.0
>
>
> support sha256 and sha512 hash functions in ts_lua plugin



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to