mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-30 03:10:06 +00:00
Merge branch 'master' of https://github.com/odin-lang/Odin
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package crypto
|
||||
|
||||
when ODIN_OS != .Linux && ODIN_OS != .OpenBSD {
|
||||
when ODIN_OS != .Linux && ODIN_OS != .OpenBSD && ODIN_OS != .Windows {
|
||||
_rand_bytes :: proc (dst: []byte) {
|
||||
unimplemented("crypto: rand_bytes not supported on this OS")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package crypto
|
||||
|
||||
import win32 "core:sys/windows"
|
||||
import "core:os"
|
||||
import "core:fmt"
|
||||
|
||||
_rand_bytes :: proc(dst: []byte) {
|
||||
ret := (os.Errno)(win32.BCryptGenRandom(nil, raw_data(dst), u32(len(dst)), win32.BCRYPT_USE_SYSTEM_PREFERRED_RNG))
|
||||
if ret != os.ERROR_NONE {
|
||||
switch ret {
|
||||
case os.ERROR_INVALID_HANDLE:
|
||||
// The handle to the first parameter is invalid.
|
||||
// This should not happen here, since we explicitly pass nil to it
|
||||
panic("crypto: BCryptGenRandom Invalid handle for hAlgorithm")
|
||||
case os.ERROR_INVALID_PARAMETER:
|
||||
// One of the parameters was invalid
|
||||
panic("crypto: BCryptGenRandom Invalid parameter")
|
||||
case:
|
||||
// Unknown error
|
||||
panic(fmt.tprintf("crypto: BCryptGenRandom failed: %d\n", ret))
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
-6
@@ -605,7 +605,7 @@ fmt_bad_verb :: proc(using fi: ^Info, verb: rune) {
|
||||
fmt_bool :: proc(using fi: ^Info, b: bool, verb: rune) {
|
||||
switch verb {
|
||||
case 't', 'v':
|
||||
io.write_string(writer, b ? "true" : "false", &fi.n)
|
||||
fmt_string(fi, b ? "true" : "false", 's')
|
||||
case:
|
||||
fmt_bad_verb(fi, verb)
|
||||
}
|
||||
@@ -943,11 +943,27 @@ fmt_float :: proc(fi: ^Info, v: f64, bit_size: int, verb: rune) {
|
||||
fmt_string :: proc(fi: ^Info, s: string, verb: rune) {
|
||||
switch verb {
|
||||
case 's', 'v':
|
||||
io.write_string(fi.writer, s, &fi.n)
|
||||
if fi.width_set && len(s) < fi.width {
|
||||
for _ in 0..<fi.width - len(s) {
|
||||
io.write_byte(fi.writer, ' ', &fi.n)
|
||||
if fi.width_set {
|
||||
if fi.width > len(s) {
|
||||
if fi.minus {
|
||||
io.write_string(fi.writer, s, &fi.n)
|
||||
}
|
||||
|
||||
for _ in 0..<fi.width - len(s) {
|
||||
io.write_byte(fi.writer, ' ', &fi.n)
|
||||
}
|
||||
|
||||
if !fi.minus {
|
||||
io.write_string(fi.writer, s, &fi.n)
|
||||
}
|
||||
}
|
||||
else {
|
||||
io.write_string(fi.writer, s[:fi.width], &fi.n)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
io.write_string(fi.writer, s, &fi.n)
|
||||
}
|
||||
|
||||
case 'q': // quoted string
|
||||
@@ -1058,7 +1074,7 @@ fmt_enum :: proc(fi: ^Info, v: any, verb: rune) {
|
||||
fmt_arg(fi, any{v.data, runtime.type_info_base(e.base).id}, verb)
|
||||
case 's', 'v':
|
||||
if str, ok := enum_value_to_string(v); ok {
|
||||
io.write_string(fi.writer, str, &fi.n)
|
||||
fmt_string(fi, str, 's')
|
||||
} else {
|
||||
io.write_string(fi.writer, "%!(BAD ENUM VALUE=", &fi.n)
|
||||
fmt_arg(fi, any{v.data, runtime.type_info_base(e.base).id}, 'i')
|
||||
|
||||
Reference in New Issue
Block a user