Class: OpenSSL::HMAC
- Inherits:
-
Object
- Object
- OpenSSL::HMAC
- Defined in:
- ossl_hmac.c
Class Method Summary collapse
Instance Method Summary collapse
- #digest ⇒ Object
- #hexdigest ⇒ Object (also: #inspect, #to_s)
- #initialize(key, digest) ⇒ Object constructor
- #update(data) ⇒ Object (also: #<<)
Constructor Details
#initialize(key, digest) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'ossl_hmac.c', line 60 static VALUE ossl_hmac_initialize(VALUE self, VALUE key, VALUE digest) { HMAC_CTX *ctx; StringValue(key); GetHMAC(self, ctx); HMAC_Init_ex(ctx, RSTRING(key)->ptr, RSTRING(key)->len, GetDigestPtr(digest), NULL); return self; } |
Class Method Details
.digest(digest, key, data) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'ossl_hmac.c', line 154 static VALUE ossl_hmac_s_digest(VALUE klass, VALUE digest, VALUE key, VALUE data) { char *buf; int buf_len; StringValue(key); StringValue(data); buf = HMAC(GetDigestPtr(digest), RSTRING(key)->ptr, RSTRING(key)->len, RSTRING(data)->ptr, RSTRING(data)->len, NULL, &buf_len); return rb_str_new(buf, buf_len); } |
.hexdigest(digest, key, data) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'ossl_hmac.c', line 168 static VALUE ossl_hmac_s_hexdigest(VALUE klass, VALUE digest, VALUE key, VALUE data) { char *buf, *hexbuf; int buf_len; VALUE hexdigest; StringValue(key); StringValue(data); buf = HMAC(GetDigestPtr(digest), RSTRING(key)->ptr, RSTRING(key)->len, RSTRING(data)->ptr, RSTRING(data)->len, NULL, &buf_len); if (string2hex(buf, buf_len, &hexbuf, NULL) != 2 * buf_len) { ossl_raise(eHMACError, "Cannot convert buf to hexbuf"); } hexdigest = ossl_buf2str(hexbuf, 2 * buf_len); return hexdigest; } |
Instance Method Details
#digest ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'ossl_hmac.c', line 119 static VALUE ossl_hmac_digest(VALUE self) { HMAC_CTX *ctx; char *buf; int buf_len; VALUE digest; GetHMAC(self, ctx); hmac_final(ctx, &buf, &buf_len); digest = ossl_buf2str(buf, buf_len); return digest; } |
#hexdigest ⇒ Object Also known as: inspect, to_s
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'ossl_hmac.c', line 134 static VALUE ossl_hmac_hexdigest(VALUE self) { HMAC_CTX *ctx; char *buf, *hexbuf; int buf_len; VALUE hexdigest; GetHMAC(self, ctx); hmac_final(ctx, &buf, &buf_len); if (string2hex(buf, buf_len, &hexbuf, NULL) != 2 * buf_len) { OPENSSL_free(buf); ossl_raise(eHMACError, "Memory alloc error"); } OPENSSL_free(buf); hexdigest = ossl_buf2str(hexbuf, 2 * buf_len); return hexdigest; } |
#update(data) ⇒ Object Also known as: <<
90 91 92 93 94 95 96 97 98 99 100 |
# File 'ossl_hmac.c', line 90 static VALUE ossl_hmac_update(VALUE self, VALUE data) { HMAC_CTX *ctx; StringValue(data); GetHMAC(self, ctx); HMAC_Update(ctx, RSTRING(data)->ptr, RSTRING(data)->len); return self; } |