From b7a0627d09e431c94aadded546bd9f3dfbe1cb1c Mon Sep 17 00:00:00 2001 From: zhibog Date: Sat, 16 Oct 2021 18:46:18 +0200 Subject: [PATCH] Remove the read_entire_file from the crypto utils and now use the one within core:os --- core/crypto/blake/blake.odin | 9 ++++----- core/crypto/blake2b/blake2b.odin | 3 +-- core/crypto/blake2s/blake2s.odin | 3 +-- core/crypto/botan/hash.odin | 19 +++++++++---------- core/crypto/gost/gost.odin | 3 +-- core/crypto/groestl/groestl.odin | 9 ++++----- core/crypto/haval/haval.odin | 10 +++++----- core/crypto/jh/jh.odin | 9 ++++----- core/crypto/keccak/keccak.odin | 9 ++++----- core/crypto/md2/md2.odin | 3 +-- core/crypto/md4/md4.odin | 2 +- core/crypto/md5/md5.odin | 2 +- core/crypto/ripemd/ripemd.odin | 8 ++++---- core/crypto/sha1/sha1.odin | 2 +- core/crypto/sha2/sha2.odin | 8 ++++---- core/crypto/sha3/sha3.odin | 9 ++++----- core/crypto/shake/shake.odin | 5 ++--- core/crypto/skein/skein.odin | 7 +++---- core/crypto/sm3/sm3.odin | 2 +- core/crypto/streebog/streebog.odin | 4 ++-- core/crypto/tiger/tiger.odin | 7 +++---- core/crypto/tiger2/tiger2.odin | 7 +++---- core/crypto/util/util.odin | 26 -------------------------- core/crypto/whirlpool/whirlpool.odin | 2 +- 24 files changed, 64 insertions(+), 104 deletions(-) diff --git a/core/crypto/blake/blake.odin b/core/crypto/blake/blake.odin index b932c9e2c..5046523b8 100644 --- a/core/crypto/blake/blake.odin +++ b/core/crypto/blake/blake.odin @@ -15,7 +15,6 @@ import "core:os" import "core:io" import "../_ctx" -import "../util" /* Context initialization and switching between the Odin implementation and the bindings @@ -272,7 +271,7 @@ hash_file_odin_28 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_28(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_28(ctx, buf[:]), ok } } @@ -313,7 +312,7 @@ hash_file_odin_32 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_32(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_32(ctx, buf[:]), ok } } @@ -354,7 +353,7 @@ hash_file_odin_48 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_48(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_48(ctx, buf[:]), ok } } @@ -395,7 +394,7 @@ hash_file_odin_64 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_64(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_64(ctx, buf[:]), ok } } diff --git a/core/crypto/blake2b/blake2b.odin b/core/crypto/blake2b/blake2b.odin index fb66e5d7c..2ac5688d5 100644 --- a/core/crypto/blake2b/blake2b.odin +++ b/core/crypto/blake2b/blake2b.odin @@ -18,7 +18,6 @@ import "core:io" import "../botan" import "../_ctx" import "../_blake2" -import "../util" /* Context initialization and switching between the Odin implementation and the bindings @@ -147,7 +146,7 @@ hash_file_odin :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, loa if !load_at_once { return hash_stream_odin(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin(ctx, buf[:]), ok } } diff --git a/core/crypto/blake2s/blake2s.odin b/core/crypto/blake2s/blake2s.odin index 0984abede..e219d8346 100644 --- a/core/crypto/blake2s/blake2s.odin +++ b/core/crypto/blake2s/blake2s.odin @@ -17,7 +17,6 @@ import "core:io" import "../_ctx" import "../_blake2" -import "../util" /* Context initialization and switching between the Odin implementation and the bindings @@ -147,7 +146,7 @@ hash_file_odin :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, loa if !load_at_once { return hash_stream_odin(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin(ctx, buf[:]), ok } } diff --git a/core/crypto/botan/hash.odin b/core/crypto/botan/hash.odin index 116ba227e..a06377927 100644 --- a/core/crypto/botan/hash.odin +++ b/core/crypto/botan/hash.odin @@ -16,7 +16,6 @@ import "core:fmt" import "core:strings" import "../_ctx" -import "../util" hash_bytes_16 :: #force_inline proc(ctx: ^_ctx.Hash_Context, data: []byte) -> [16]byte { hash: [16]byte @@ -112,7 +111,7 @@ hash_file_16 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, load_ if !load_at_once { return hash_stream_16(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_16(ctx, buf[:]), ok } } @@ -123,7 +122,7 @@ hash_file_20 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, load_ if !load_at_once { return hash_stream_20(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_20(ctx, buf[:]), ok } } @@ -134,7 +133,7 @@ hash_file_24 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, load_ if !load_at_once { return hash_stream_24(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_24(ctx, buf[:]), ok } } @@ -145,7 +144,7 @@ hash_file_28 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, load_ if !load_at_once { return hash_stream_28(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_28(ctx, buf[:]), ok } } @@ -156,7 +155,7 @@ hash_file_32 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, load_ if !load_at_once { return hash_stream_32(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_32(ctx, buf[:]), ok } } @@ -167,7 +166,7 @@ hash_file_48 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, load_ if !load_at_once { return hash_stream_48(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_48(ctx, buf[:]), ok } } @@ -178,7 +177,7 @@ hash_file_64 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, load_ if !load_at_once { return hash_stream_64(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_64(ctx, buf[:]), ok } } @@ -189,7 +188,7 @@ hash_file_128 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, load if !load_at_once { return hash_stream_128(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_128(ctx, buf[:]), ok } } @@ -200,7 +199,7 @@ hash_file_slice :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, bi if !load_at_once { return hash_stream_slice(ctx, os.stream_from_handle(hd), bit_size, allocator) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_slice(ctx, buf[:], bit_size, allocator), ok } } diff --git a/core/crypto/gost/gost.odin b/core/crypto/gost/gost.odin index 49b84181c..00a8fdc3d 100644 --- a/core/crypto/gost/gost.odin +++ b/core/crypto/gost/gost.odin @@ -17,7 +17,6 @@ import "core:io" import "../botan" import "../_ctx" -import "../util" /* Context initialization and switching between the Odin implementation and the bindings @@ -140,7 +139,7 @@ hash_file_odin :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, loa if !load_at_once { return hash_stream_odin(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin(ctx, buf[:]), ok } } diff --git a/core/crypto/groestl/groestl.odin b/core/crypto/groestl/groestl.odin index d0397952b..8c6d73be8 100644 --- a/core/crypto/groestl/groestl.odin +++ b/core/crypto/groestl/groestl.odin @@ -15,7 +15,6 @@ import "core:os" import "core:io" import "../_ctx" -import "../util" /* Context initialization and switching between the Odin implementation and the bindings @@ -269,7 +268,7 @@ hash_file_odin_28 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_28(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_28(ctx, buf[:]), ok } } @@ -310,7 +309,7 @@ hash_file_odin_32 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_32(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_32(ctx, buf[:]), ok } } @@ -351,7 +350,7 @@ hash_file_odin_48 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_48(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_48(ctx, buf[:]), ok } } @@ -392,7 +391,7 @@ hash_file_odin_64 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_64(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_64(ctx, buf[:]), ok } } diff --git a/core/crypto/haval/haval.odin b/core/crypto/haval/haval.odin index d174812e9..9c52ae1e4 100644 --- a/core/crypto/haval/haval.odin +++ b/core/crypto/haval/haval.odin @@ -651,7 +651,7 @@ hash_file_odin_16 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_16(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_16(ctx, buf[:]), ok } } @@ -694,7 +694,7 @@ hash_file_odin_20 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_20(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_20(ctx, buf[:]), ok } } @@ -737,7 +737,7 @@ hash_file_odin_24 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_24(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_24(ctx, buf[:]), ok } } @@ -780,7 +780,7 @@ hash_file_odin_28 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_28(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_28(ctx, buf[:]), ok } } @@ -823,7 +823,7 @@ hash_file_odin_32 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_32(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_32(ctx, buf[:]), ok } } diff --git a/core/crypto/jh/jh.odin b/core/crypto/jh/jh.odin index 3002d2641..3ff409962 100644 --- a/core/crypto/jh/jh.odin +++ b/core/crypto/jh/jh.odin @@ -15,7 +15,6 @@ import "core:os" import "core:io" import "../_ctx" -import "../util" /* Context initialization and switching between the Odin implementation and the bindings @@ -269,7 +268,7 @@ hash_file_odin_28 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_28(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_28(ctx, buf[:]), ok } } @@ -310,7 +309,7 @@ hash_file_odin_32 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_32(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_32(ctx, buf[:]), ok } } @@ -351,7 +350,7 @@ hash_file_odin_48 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_48(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_48(ctx, buf[:]), ok } } @@ -392,7 +391,7 @@ hash_file_odin_64 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_64(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_64(ctx, buf[:]), ok } } diff --git a/core/crypto/keccak/keccak.odin b/core/crypto/keccak/keccak.odin index 172f3bdef..37aa7c12e 100644 --- a/core/crypto/keccak/keccak.odin +++ b/core/crypto/keccak/keccak.odin @@ -18,7 +18,6 @@ import "core:io" import "../botan" import "../_ctx" import "../_sha3" -import "../util" /* Context initialization and switching between the Odin implementation and the bindings @@ -258,7 +257,7 @@ hash_file_odin_28 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_28(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_28(ctx, buf[:]), ok } } @@ -299,7 +298,7 @@ hash_file_odin_32 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_32(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_32(ctx, buf[:]), ok } } @@ -340,7 +339,7 @@ hash_file_odin_48 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_48(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_48(ctx, buf[:]), ok } } @@ -381,7 +380,7 @@ hash_file_odin_64 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_64(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_64(ctx, buf[:]), ok } } diff --git a/core/crypto/md2/md2.odin b/core/crypto/md2/md2.odin index 06356536f..ceca0f58b 100644 --- a/core/crypto/md2/md2.odin +++ b/core/crypto/md2/md2.odin @@ -15,7 +15,6 @@ import "core:os" import "core:io" import "../_ctx" -import "../util" /* Context initialization and switching between the Odin implementation and the bindings @@ -145,7 +144,7 @@ hash_file_odin :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, loa if !load_at_once { return hash_stream_odin(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin(ctx, buf[:]), ok } } diff --git a/core/crypto/md4/md4.odin b/core/crypto/md4/md4.odin index 01288d550..bc012caea 100644 --- a/core/crypto/md4/md4.odin +++ b/core/crypto/md4/md4.odin @@ -146,7 +146,7 @@ hash_file_odin :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, loa if !load_at_once { return hash_stream_odin(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin(ctx, buf[:]), ok } } diff --git a/core/crypto/md5/md5.odin b/core/crypto/md5/md5.odin index 6c1dfdd1f..78da3fe33 100644 --- a/core/crypto/md5/md5.odin +++ b/core/crypto/md5/md5.odin @@ -146,7 +146,7 @@ hash_file_odin :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, loa if !load_at_once { return hash_stream_odin(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin(ctx, buf[:]), ok } } diff --git a/core/crypto/ripemd/ripemd.odin b/core/crypto/ripemd/ripemd.odin index c9e3978fd..fe480e5a9 100644 --- a/core/crypto/ripemd/ripemd.odin +++ b/core/crypto/ripemd/ripemd.odin @@ -240,7 +240,7 @@ hash_file_odin_16 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_16(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_16(ctx, buf[:]), ok } } @@ -281,7 +281,7 @@ hash_file_odin_20 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_20(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_20(ctx, buf[:]), ok } } @@ -322,7 +322,7 @@ hash_file_odin_32 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_32(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_32(ctx, buf[:]), ok } } @@ -363,7 +363,7 @@ hash_file_odin_40 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_40(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_40(ctx, buf[:]), ok } } diff --git a/core/crypto/sha1/sha1.odin b/core/crypto/sha1/sha1.odin index ee2878c0e..022859309 100644 --- a/core/crypto/sha1/sha1.odin +++ b/core/crypto/sha1/sha1.odin @@ -146,7 +146,7 @@ hash_file_odin :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, loa if !load_at_once { return hash_stream_odin(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin(ctx, buf[:]), ok } } diff --git a/core/crypto/sha2/sha2.odin b/core/crypto/sha2/sha2.odin index 2f7d44a21..2ddbcf27a 100644 --- a/core/crypto/sha2/sha2.odin +++ b/core/crypto/sha2/sha2.odin @@ -274,7 +274,7 @@ hash_file_odin_28 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_28(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_28(ctx, buf[:]), ok } } @@ -315,7 +315,7 @@ hash_file_odin_32 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_32(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_32(ctx, buf[:]), ok } } @@ -356,7 +356,7 @@ hash_file_odin_48 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_48(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_48(ctx, buf[:]), ok } } @@ -397,7 +397,7 @@ hash_file_odin_64 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_64(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_64(ctx, buf[:]), ok } } diff --git a/core/crypto/sha3/sha3.odin b/core/crypto/sha3/sha3.odin index 1754eab24..c37e369c9 100644 --- a/core/crypto/sha3/sha3.odin +++ b/core/crypto/sha3/sha3.odin @@ -18,7 +18,6 @@ import "core:io" import "../botan" import "../_ctx" import "../_sha3" -import "../util" /* Context initialization and switching between the Odin implementation and the bindings @@ -258,7 +257,7 @@ hash_file_odin_28 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_28(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_28(ctx, buf[:]), ok } } @@ -299,7 +298,7 @@ hash_file_odin_32 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_32(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_32(ctx, buf[:]), ok } } @@ -340,7 +339,7 @@ hash_file_odin_48 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_48(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_48(ctx, buf[:]), ok } } @@ -381,7 +380,7 @@ hash_file_odin_64 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_64(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_64(ctx, buf[:]), ok } } diff --git a/core/crypto/shake/shake.odin b/core/crypto/shake/shake.odin index 93e24c8e1..44dd3d40d 100644 --- a/core/crypto/shake/shake.odin +++ b/core/crypto/shake/shake.odin @@ -18,7 +18,6 @@ import "core:io" import "../botan" import "../_ctx" import "../_sha3" -import "../util" /* Context initialization and switching between the Odin implementation and the bindings @@ -186,7 +185,7 @@ hash_file_odin_16 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_16(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_16(ctx, buf[:]), ok } } @@ -229,7 +228,7 @@ hash_file_odin_32 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_32(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_32(ctx, buf[:]), ok } } diff --git a/core/crypto/skein/skein.odin b/core/crypto/skein/skein.odin index 69fbd1caf..45623d480 100644 --- a/core/crypto/skein/skein.odin +++ b/core/crypto/skein/skein.odin @@ -18,7 +18,6 @@ import "core:io" import "../botan" import "../_ctx" -import "../util" /* Context initialization and switching between the Odin implementation and the bindings @@ -275,7 +274,7 @@ hash_file_skein256_odin :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Ha if !load_at_once { return hash_stream_skein256_odin(ctx, os.stream_from_handle(hd), bit_size, allocator) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_skein256_odin(ctx, buf[:], bit_size, allocator), ok } } @@ -320,7 +319,7 @@ hash_file_skein512_odin :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Ha if !load_at_once { return hash_stream_skein512_odin(ctx, os.stream_from_handle(hd), bit_size, allocator) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_skein512_odin(ctx, buf[:], bit_size, allocator), ok } } @@ -365,7 +364,7 @@ hash_file_skein1024_odin :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.H if !load_at_once { return hash_stream_skein512_odin(ctx, os.stream_from_handle(hd), bit_size, allocator) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_skein512_odin(ctx, buf[:], bit_size, allocator), ok } } diff --git a/core/crypto/sm3/sm3.odin b/core/crypto/sm3/sm3.odin index 1445075c1..bd1f6f98a 100644 --- a/core/crypto/sm3/sm3.odin +++ b/core/crypto/sm3/sm3.odin @@ -145,7 +145,7 @@ hash_file_odin :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, loa if !load_at_once { return hash_stream_odin(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin(ctx, buf[:]), ok } } diff --git a/core/crypto/streebog/streebog.odin b/core/crypto/streebog/streebog.odin index 9f03d5a12..385fbdc44 100644 --- a/core/crypto/streebog/streebog.odin +++ b/core/crypto/streebog/streebog.odin @@ -190,7 +190,7 @@ hash_file_odin_32 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_32(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_32(ctx, buf[:]), ok } } @@ -231,7 +231,7 @@ hash_file_odin_64 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_64(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_64(ctx, buf[:]), ok } } diff --git a/core/crypto/tiger/tiger.odin b/core/crypto/tiger/tiger.odin index f50e0aa07..24c6c2e6f 100644 --- a/core/crypto/tiger/tiger.odin +++ b/core/crypto/tiger/tiger.odin @@ -17,7 +17,6 @@ import "core:io" import "../botan" import "../_ctx" import "../_tiger" -import "../util" /* Context initialization and switching between the Odin implementation and the bindings @@ -204,7 +203,7 @@ hash_file_odin_16 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_16(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_16(ctx, buf[:]), ok } } @@ -245,7 +244,7 @@ hash_file_odin_20 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_20(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_20(ctx, buf[:]), ok } } @@ -286,7 +285,7 @@ hash_file_odin_24 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_24(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_24(ctx, buf[:]), ok } } diff --git a/core/crypto/tiger2/tiger2.odin b/core/crypto/tiger2/tiger2.odin index 0e218e5e7..b7fc301ed 100644 --- a/core/crypto/tiger2/tiger2.odin +++ b/core/crypto/tiger2/tiger2.odin @@ -16,7 +16,6 @@ import "core:io" import "../_ctx" import "../_tiger" -import "../util" /* Context initialization and switching between the Odin implementation and the bindings @@ -204,7 +203,7 @@ hash_file_odin_16 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_16(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_16(ctx, buf[:]), ok } } @@ -245,7 +244,7 @@ hash_file_odin_20 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_20(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_20(ctx, buf[:]), ok } } @@ -286,7 +285,7 @@ hash_file_odin_24 :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, if !load_at_once { return hash_stream_odin_24(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin_24(ctx, buf[:]), ok } } diff --git a/core/crypto/util/util.odin b/core/crypto/util/util.odin index e6c6085ad..6273a232e 100644 --- a/core/crypto/util/util.odin +++ b/core/crypto/util/util.odin @@ -11,7 +11,6 @@ package util */ import "core:mem" -import "core:os" // @note(bp): this can replace the other two cast_slice :: #force_inline proc "contextless" ($D: typeid/[]$DE, src: $S/[]$SE) -> D { @@ -143,28 +142,3 @@ XOR_BUF :: #force_inline proc "contextless" (input, output: []byte) { output[i] ~= input[i] } } - -// Taken from core:os and changed to just take a file handle -read_entire_file :: proc(fd: os.Handle, allocator := context.allocator) -> (data: []byte, success: bool) { - length: i64 - err: os.Errno - if length, err = os.file_size(fd); err != 0 { - return nil, false - } - - if length <= 0 { - return nil, true - } - - data = make([]byte, int(length), allocator) - if data == nil { - return nil, false - } - - bytes_read, read_err := os.read(fd, data) - if read_err != os.ERROR_NONE { - delete(data) - return nil, false - } - return data[:bytes_read], true -} \ No newline at end of file diff --git a/core/crypto/whirlpool/whirlpool.odin b/core/crypto/whirlpool/whirlpool.odin index b9968492e..ce0123318 100644 --- a/core/crypto/whirlpool/whirlpool.odin +++ b/core/crypto/whirlpool/whirlpool.odin @@ -142,7 +142,7 @@ hash_file_odin :: #force_inline proc(ctx: ^_ctx.Hash_Context, hd: os.Handle, loa if !load_at_once { return hash_stream_odin(ctx, os.stream_from_handle(hd)) } else { - if buf, ok := util.read_entire_file(hd); ok { + if buf, ok := os.read_entire_file(hd); ok { return hash_bytes_odin(ctx, buf[:]), ok } }