|
1 | | -// feedback-o-tron FFI Implementation |
| 1 | +// FEEDBACK_O_TRON FFI Implementation |
2 | 2 | // |
3 | 3 | // This module implements the C-compatible FFI declared in src/abi/Foreign.idr |
4 | 4 | // All types and layouts must match the Idris2 ABI definitions. |
|
8 | 8 | const std = @import("std"); |
9 | 9 |
|
10 | 10 | // Version information (keep in sync with project) |
11 | | -const VERSION = "1.0.0"; |
12 | | -const BUILD_INFO = "feedback-o-tron built with Zig " ++ @import("builtin").zig_version_string; |
| 11 | +const VERSION = "0.1.0"; |
| 12 | +const BUILD_INFO = "FEEDBACK_O_TRON built with Zig " ++ @import("builtin").zig_version_string; |
13 | 13 |
|
14 | 14 | /// Thread-local error storage |
15 | 15 | threadlocal var last_error: ?[]const u8 = null; |
@@ -248,80 +248,6 @@ export fn feedback_o_tron_is_initialized(handle: ?*Handle) u32 { |
248 | 248 | return if (h.initialized) 1 else 0; |
249 | 249 | } |
250 | 250 |
|
251 | | -//============================================================================== |
252 | | -// Feedback-Specific Operations |
253 | | -//============================================================================== |
254 | | - |
255 | | -/// Compute SHA-256 hash for deduplication (matches Elixir Deduplicator) |
256 | | -/// Returns first 16 hex chars of SHA-256(input), or null on error. |
257 | | -/// Caller must free the returned string via feedback_o_tron_free_string. |
258 | | -export fn feedback_o_tron_compute_hash( |
259 | | - input: ?[*]const u8, |
260 | | - len: u32, |
261 | | -) ?[*:0]const u8 { |
262 | | - const buf = input orelse { |
263 | | - setError("Null input buffer"); |
264 | | - return null; |
265 | | - }; |
266 | | - |
267 | | - const data = buf[0..len]; |
268 | | - var digest: [32]u8 = undefined; |
269 | | - std.crypto.hash.sha2.Sha256.hash(data, &digest, .{}); |
270 | | - |
271 | | - // Encode first 8 bytes as 16 hex chars |
272 | | - const allocator = std.heap.c_allocator; |
273 | | - const hex = allocator.alloc(u8, 17) catch { |
274 | | - setError("Failed to allocate hash string"); |
275 | | - return null; |
276 | | - }; |
277 | | - |
278 | | - const hex_chars = "0123456789abcdef"; |
279 | | - for (0..8) |i| { |
280 | | - hex[i * 2] = hex_chars[digest[i] >> 4]; |
281 | | - hex[i * 2 + 1] = hex_chars[digest[i] & 0x0f]; |
282 | | - } |
283 | | - hex[16] = 0; // null terminator |
284 | | - |
285 | | - clearError(); |
286 | | - return @ptrCast(hex.ptr); |
287 | | -} |
288 | | - |
289 | | -/// Generate a cryptographically random submission ID (11 chars, URL-safe base64). |
290 | | -/// Caller must free the returned string via feedback_o_tron_free_string. |
291 | | -export fn feedback_o_tron_generate_id() ?[*:0]const u8 { |
292 | | - var bytes: [8]u8 = undefined; |
293 | | - std.crypto.random.bytes(&bytes); |
294 | | - |
295 | | - const allocator = std.heap.c_allocator; |
296 | | - const encoder = std.base64.url_safe_no_pad; |
297 | | - const encoded_len = encoder.calcSize(8); |
298 | | - const result = allocator.alloc(u8, encoded_len + 1) catch { |
299 | | - setError("Failed to allocate ID string"); |
300 | | - return null; |
301 | | - }; |
302 | | - |
303 | | - _ = encoder.encode(result[0..encoded_len], &bytes); |
304 | | - result[encoded_len] = 0; |
305 | | - |
306 | | - clearError(); |
307 | | - return @ptrCast(result.ptr); |
308 | | -} |
309 | | - |
310 | | -/// Validate that a URL uses HTTPS (security requirement). |
311 | | -/// Returns 1 if valid HTTPS, 0 otherwise. |
312 | | -export fn feedback_o_tron_validate_https( |
313 | | - url: ?[*]const u8, |
314 | | - len: u32, |
315 | | -) u32 { |
316 | | - const buf = url orelse return 0; |
317 | | - const data = buf[0..len]; |
318 | | - |
319 | | - if (data.len >= 8 and std.mem.eql(u8, data[0..8], "https://")) { |
320 | | - return 1; |
321 | | - } |
322 | | - return 0; |
323 | | -} |
324 | | - |
325 | 251 | //============================================================================== |
326 | 252 | // Tests |
327 | 253 | //============================================================================== |
|
0 commit comments