Skip to content

Commit 615356b

Browse files
committed
wip helper functions logic
1 parent 031ce2f commit 615356b

File tree

5 files changed

+716
-16
lines changed

5 files changed

+716
-16
lines changed

lib/imagekit/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def initialize(
100100

101101
base_url ||= "https://api.imagekit.io"
102102

103-
if private_key.nil?
103+
if private_key.nil? || private_key.to_s.empty?
104104
raise ArgumentError.new("private_key is required, and can be set via environ: \"IMAGEKIT_PRIVATE_KEY\"")
105105
end
106106

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
require "openssl"
4+
require "digest"
5+
6+
module Imagekit
7+
module Helpers
8+
# Crypto utilities for ImageKit SDK
9+
# Provides HMAC-SHA1 functionality for URL signing and authentication
10+
module CryptoUtils
11+
class << self
12+
# Creates an HMAC-SHA1 hash
13+
#
14+
# @param key [String] The secret key for HMAC generation
15+
# @param data [String] The data to be signed
16+
# @return [String] Hex-encoded HMAC-SHA1 hash
17+
# @raise [StandardError] if HMAC generation fails
18+
def create_hmac_sha1(key, data)
19+
OpenSSL::HMAC.hexdigest("SHA1", key, data)
20+
rescue StandardError => e
21+
raise StandardError, "Failed to generate HMAC-SHA1 signature: #{e.message}"
22+
end
23+
end
24+
end
25+
end
26+
end

0 commit comments

Comments
 (0)