aboutsummaryrefslogtreecommitdiff
path: root/core/crypto
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-09-19 12:06:31 +0100
committergingerBill <bill@gingerbill.org>2024-09-19 12:06:31 +0100
commit244907149aff369df9d63728ab42e6add4c83463 (patch)
treed60c60e54265b77387638b3b619b5293a09a7f37 /core/crypto
parent8814170edff5c7c70d17d5edf789bc478311d906 (diff)
Move os stuff to OS specific files
Diffstat (limited to 'core/crypto')
-rw-r--r--core/crypto/hash/hash.odin42
-rw-r--r--core/crypto/hash/hash_freestanding.odin10
-rw-r--r--core/crypto/hash/hash_os.odin37
3 files changed, 51 insertions, 38 deletions
diff --git a/core/crypto/hash/hash.odin b/core/crypto/hash/hash.odin
index f7671270a..d47f0ab46 100644
--- a/core/crypto/hash/hash.odin
+++ b/core/crypto/hash/hash.odin
@@ -1,16 +1,15 @@
package crypto_hash
/*
- Copyright 2021 zhibog
- Made available under the BSD-3 license.
+ Copyright 2021 zhibog
+ Made available under the BSD-3 license.
- List of contributors:
- zhibog, dotbmp: Initial implementation.
+ List of contributors:
+ zhibog, dotbmp: Initial implementation.
*/
import "core:io"
import "core:mem"
-import "core:os"
// hash_bytes will hash the given input and return the computed digest
// in a newly allocated slice.
@@ -87,36 +86,3 @@ hash_stream :: proc(
return dst, io.Error.None
}
-
-// hash_file will read the file provided by the given handle and return the
-// computed digest in a newly allocated slice.
-hash_file :: proc(
- algorithm: Algorithm,
- hd: os.Handle,
- load_at_once := false,
- allocator := context.allocator,
-) -> (
- []byte,
- io.Error,
-) {
- if !load_at_once {
- return hash_stream(algorithm, os.stream_from_handle(hd), allocator)
- }
-
- buf, ok := os.read_entire_file(hd, allocator)
- if !ok {
- return nil, io.Error.Unknown
- }
- defer delete(buf, allocator)
-
- return hash_bytes(algorithm, buf, allocator), io.Error.None
-}
-
-hash :: proc {
- hash_stream,
- hash_file,
- hash_bytes,
- hash_string,
- hash_bytes_to_buffer,
- hash_string_to_buffer,
-}
diff --git a/core/crypto/hash/hash_freestanding.odin b/core/crypto/hash/hash_freestanding.odin
new file mode 100644
index 000000000..15fd6ab4f
--- /dev/null
+++ b/core/crypto/hash/hash_freestanding.odin
@@ -0,0 +1,10 @@
+//+build freestanding
+package crypto_hash
+
+hash :: proc {
+ hash_stream,
+ hash_bytes,
+ hash_string,
+ hash_bytes_to_buffer,
+ hash_string_to_buffer,
+}
diff --git a/core/crypto/hash/hash_os.odin b/core/crypto/hash/hash_os.odin
new file mode 100644
index 000000000..d69f21237
--- /dev/null
+++ b/core/crypto/hash/hash_os.odin
@@ -0,0 +1,37 @@
+//+build !freestanding
+package crypto_hash
+
+import "core:os"
+
+// hash_file will read the file provided by the given handle and return the
+// computed digest in a newly allocated slice.
+hash_file :: proc(
+ algorithm: Algorithm,
+ hd: os.Handle,
+ load_at_once := false,
+ allocator := context.allocator,
+) -> (
+ []byte,
+ io.Error,
+) {
+ if !load_at_once {
+ return hash_stream(algorithm, os.stream_from_handle(hd), allocator)
+ }
+
+ buf, ok := os.read_entire_file(hd, allocator)
+ if !ok {
+ return nil, io.Error.Unknown
+ }
+ defer delete(buf, allocator)
+
+ return hash_bytes(algorithm, buf, allocator), io.Error.None
+}
+
+hash :: proc {
+ hash_stream,
+ hash_file,
+ hash_bytes,
+ hash_string,
+ hash_bytes_to_buffer,
+ hash_string_to_buffer,
+}