Module: Seedfaker
- Defined in:
- lib/seedfaker.rb
Defined Under Namespace
Classes: SeedFaker
Constant Summary collapse
- NATIVE_CHECKSUM =
@checksum-start CI replaces this with real SHA256 before building gem. Empty = dev (running from source). Filled = production (verify mandatory).
""
Class Method Summary collapse
-
.find_library ⇒ Object
@checksum-end.
Class Method Details
.find_library ⇒ Object
@checksum-end
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/seedfaker.rb', line 142 def self.find_library os = case RbConfig::CONFIG["host_os"] when /darwin/ then "darwin" when /linux/ then "linux" when /mswin|mingw|cygwin/ then "windows" else RbConfig::CONFIG["host_os"] end cpu = RbConfig::CONFIG["host_cpu"] arch = if cpu.match?(/x86_64|amd64/) then "x86_64" elsif cpu.match?(/arm64|aarch64/) then "arm64" else cpu end ext = case os when "darwin" then "dylib" when "windows" then "dll" else "so" end name = "libseedfaker_ffi.#{ext}" target = "#{os}-#{arch}" # Gem layout: bin/{os}-{arch}/libseedfaker_ffi.{ext} bundled = File.join(__dir__, "..", "bin", target, name) if NATIVE_CHECKSUM != "" # Production: bundled binary only, verify SHA256, no exceptions. raise "seedfaker: bundled library not found at #{bundled}" unless File.exist?(bundled) actual = Digest::SHA256.hexdigest(File.binread(bundled)) unless actual == NATIVE_CHECKSUM raise "seedfaker: native library integrity check failed. " \ "Expected #{NATIVE_CHECKSUM[0, 16]}..., got #{actual[0, 16]}... " \ "Reinstall the package or verify your installation." end return bundled end # Dev: NATIVE_CHECKSUM empty = running from source or flat-layout gem. return bundled if File.exist?(bundled) project = File.join(__dir__, "..", "..", "..", "rust", "target", "release", name) return project if File.exist?(project) nil end |