@@ -53,7 +53,7 @@ static int doHashHMAC(lua_State *L, CCHmacAlgorithm algorithm, CC_LONG resultLen
53
53
// / * data - A string containing some data to hash
54
54
// /
55
55
// / Returns:
56
- // / * A string containing the hash of the supplied data
56
+ // / * A string containing the hash of the supplied data, encoded as hexadecimal
57
57
static int hash_sha1 (lua_State *L) {
58
58
return doHash (L, CC_SHA1_DIGEST_LENGTH, CC_SHA1);
59
59
}
@@ -66,7 +66,7 @@ static int hash_sha1(lua_State *L) {
66
66
// / * data - A string containing some data to hash
67
67
// /
68
68
// / Returns:
69
- // / * A string containing the hash of the supplied data
69
+ // / * A string containing the hash of the supplied data, encoded as hexadecimal
70
70
static int hash_sha256 (lua_State *L) {
71
71
return doHash (L, CC_SHA256_DIGEST_LENGTH, CC_SHA256);
72
72
}
@@ -79,7 +79,7 @@ static int hash_sha256(lua_State *L) {
79
79
// / * data - A string containing some data to hash
80
80
// /
81
81
// / Returns:
82
- // / * A string containing the hash of the supplied data
82
+ // / * A string containing the hash of the supplied data, encoded as hexadecimal
83
83
static int hash_sha512 (lua_State *L) {
84
84
return doHash (L, CC_SHA512_DIGEST_LENGTH, CC_SHA512);
85
85
}
@@ -92,14 +92,105 @@ static int hash_sha512(lua_State *L) {
92
92
// / * data - A string containing some data to hash
93
93
// /
94
94
// / Returns:
95
- // / * A string containing the hash of the supplied data
95
+ // / * A string containing the hash of the supplied data, encoded as hexadecimal
96
96
static int hash_md5 (lua_State *L) {
97
97
#pragma clang diagnostic push
98
98
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
99
99
return doHash (L, CC_MD5_DIGEST_LENGTH, CC_MD5);
100
100
#pragma clang diagnostic pop
101
101
}
102
102
103
+ // / hs.hash.bSHA1(data) -> data
104
+ // / Function
105
+ // / Calculates a binary SHA1 hash
106
+ // /
107
+ // / Parameters:
108
+ // / * data - A string containing some data to hash
109
+ // /
110
+ // / Returns:
111
+ // / * A string containing the binary hash of the supplied data
112
+ static int hash_bsha1 (lua_State *L) {
113
+ LuaSkin *skin = [LuaSkin sharedWithState: L];
114
+ [skin checkArgs: LS_TSTRING, LS_TBREAK];
115
+
116
+ NSData *dataIn = [skin toNSObjectAtIndex: 1 withOptions: LS_NSLuaStringAsDataOnly];
117
+
118
+ NSMutableData *macOut = [NSMutableData dataWithLength: CC_SHA1_DIGEST_LENGTH];
119
+ CC_SHA1 (dataIn.bytes , (CC_LONG)dataIn.length , macOut.mutableBytes );
120
+
121
+ [skin pushNSObject: macOut];
122
+ return 1 ;
123
+ }
124
+
125
+ // / hs.hash.bSHA256(data) -> data
126
+ // / Function
127
+ // / Calculates a binary SHA256 hash
128
+ // /
129
+ // / Parameters:
130
+ // / * data - A string containing some data to hash
131
+ // /
132
+ // / Returns:
133
+ // / * A string containing the binary hash of the supplied data
134
+ static int hash_bsha256 (lua_State *L) {
135
+ LuaSkin *skin = [LuaSkin sharedWithState: L];
136
+ [skin checkArgs: LS_TSTRING, LS_TBREAK];
137
+
138
+ NSData *dataIn = [skin toNSObjectAtIndex: 1 withOptions: LS_NSLuaStringAsDataOnly];
139
+
140
+ NSMutableData *macOut = [NSMutableData dataWithLength: CC_SHA256_DIGEST_LENGTH];
141
+ CC_SHA256 (dataIn.bytes , (CC_LONG)dataIn.length , macOut.mutableBytes );
142
+
143
+ [skin pushNSObject: macOut];
144
+ return 1 ;
145
+ }
146
+
147
+ // / hs.hash.bSHA512(data) -> data
148
+ // / Function
149
+ // / Calculates a binary SHA512 hash
150
+ // /
151
+ // / Parameters:
152
+ // / * data - A string containing some data to hash
153
+ // /
154
+ // / Returns:
155
+ // / * A string containing the binary hash of the supplied data
156
+ static int hash_bsha512 (lua_State *L) {
157
+ LuaSkin *skin = [LuaSkin sharedWithState: L];
158
+ [skin checkArgs: LS_TSTRING, LS_TBREAK];
159
+
160
+ NSData *dataIn = [skin toNSObjectAtIndex: 1 withOptions: LS_NSLuaStringAsDataOnly];
161
+
162
+ NSMutableData *macOut = [NSMutableData dataWithLength: CC_SHA512_DIGEST_LENGTH];
163
+ CC_SHA512 (dataIn.bytes , (CC_LONG)dataIn.length , macOut.mutableBytes );
164
+
165
+ [skin pushNSObject: macOut];
166
+ return 1 ;
167
+ }
168
+
169
+ // / hs.hash.bMD5(data) -> data
170
+ // / Function
171
+ // / Calculates a binary MD5 hash
172
+ // /
173
+ // / Parameters:
174
+ // / * data - A string containing some data to hash
175
+ // /
176
+ // / Returns:
177
+ // / * A string containing the binary hash of the supplied data
178
+ static int hash_bmd5 (lua_State *L) {
179
+ LuaSkin *skin = [LuaSkin sharedWithState: L];
180
+ [skin checkArgs: LS_TSTRING, LS_TBREAK];
181
+
182
+ NSData *dataIn = [skin toNSObjectAtIndex: 1 withOptions: LS_NSLuaStringAsDataOnly];
183
+
184
+ NSMutableData *macOut = [NSMutableData dataWithLength: CC_MD5_DIGEST_LENGTH];
185
+ #pragma clang diagnostic push
186
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
187
+ CC_MD5 (dataIn.bytes , (CC_LONG)dataIn.length , macOut.mutableBytes );
188
+ #pragma clang diagnostic pop
189
+
190
+ [skin pushNSObject: macOut];
191
+ return 1 ;
192
+ }
193
+
103
194
// / hs.hash.hmacSHA1(key, data) -> string
104
195
// / Function
105
196
// / Calculates an HMAC using a key and a SHA1 hash
@@ -162,6 +253,11 @@ static int hash_md5_hmac(lua_State *L) {
162
253
{" SHA512" , hash_sha512},
163
254
{" MD5" , hash_md5},
164
255
256
+ {" bSHA1" , hash_bsha1},
257
+ {" bSHA256" , hash_bsha256},
258
+ {" bSHA512" , hash_bsha512},
259
+ {" bMD5" , hash_bmd5},
260
+
165
261
{" hmacSHA1" , hash_sha1_hmac},
166
262
{" hmacSHA256" , hash_sha256_hmac},
167
263
{" hmacSHA512" , hash_sha512_hmac},
0 commit comments