mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vlib: run vfmt over vlib files, so that v doc -m vlib/
can run without warnings
This commit is contained in:
@ -1,23 +1,18 @@
|
||||
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
// Package subtle implements functions that are often useful in cryptographic
|
||||
// code but require careful thought to use correctly.
|
||||
|
||||
module subtle
|
||||
|
||||
// NOTE: require unsafe in future
|
||||
|
||||
// any_overlap reports whether x and y share memory at any (not necessarily
|
||||
// corresponding) index. The memory beyond the slice length is ignored.
|
||||
pub fn any_overlap(x, y []byte) bool {
|
||||
pub fn any_overlap(x []byte, y []byte) bool {
|
||||
// NOTE: Remember to come back to this (joe-c)
|
||||
return x.len > 0 && y.len > 0 &&
|
||||
// &x.data[0] <= &y.data[y.len-1] &&
|
||||
// &y.data[0] <= &x.data[x.len-1]
|
||||
unsafe { &x[0] <= &y[y.len-1] &&
|
||||
&y[0] <= &x[x.len-1] }
|
||||
return x.len > 0 && y.len > 0 && // &x.data[0] <= &y.data[y.len-1] &&
|
||||
// &y.data[0] <= &x.data[x.len-1]
|
||||
unsafe {&x[0] <= &y[y.len - 1] && &y[0] <= &x[x.len - 1]}
|
||||
}
|
||||
|
||||
// inexact_overlap reports whether x and y share memory at any non-corresponding
|
||||
@ -26,8 +21,8 @@ pub fn any_overlap(x, y []byte) bool {
|
||||
//
|
||||
// inexact_overlap can be used to implement the requirements of the crypto/cipher
|
||||
// AEAD, Block, BlockMode and Stream interfaces.
|
||||
pub fn inexact_overlap(x, y []byte) bool {
|
||||
if x.len == 0 || y.len == 0 || unsafe { &x[0] == &y[0] } {
|
||||
pub fn inexact_overlap(x []byte, y []byte) bool {
|
||||
if x.len == 0 || y.len == 0 || unsafe {&x[0] == &y[0]} {
|
||||
return false
|
||||
}
|
||||
return any_overlap(x, y)
|
||||
|
@ -1,25 +1,25 @@
|
||||
module subtle
|
||||
|
||||
// constant_time_byte_eq returns 1 when x == y.
|
||||
pub fn constant_time_byte_eq(x, y byte) int {
|
||||
pub fn constant_time_byte_eq(x byte, y byte) int {
|
||||
return int((u32(x ^ y) - 1) >> 31)
|
||||
}
|
||||
|
||||
// constant_time_eq returns 1 when x == y.
|
||||
pub fn constant_time_eq(x, y int) int {
|
||||
pub fn constant_time_eq(x int, y int) int {
|
||||
return int((u64(u32(x ^ y)) - 1) >> 63)
|
||||
}
|
||||
|
||||
// constant_time_select returns x when v == 1, and y when v == 0.
|
||||
// it is undefined when v is any other value
|
||||
pub fn constant_time_select(v, x, y int) int {
|
||||
pub fn constant_time_select(v int, x int, y int) int {
|
||||
return (~(v - 1) & x) | ((v - 1) & y)
|
||||
}
|
||||
|
||||
// constant_time_compare returns 1 when x and y have equal contents.
|
||||
// The runtime of this function is proportional of the length of x and y.
|
||||
// It is *NOT* dependent on their content.
|
||||
pub fn constant_time_compare(x, y []byte) int {
|
||||
pub fn constant_time_compare(x []byte, y []byte) int {
|
||||
if x.len != y.len {
|
||||
return 0
|
||||
}
|
||||
@ -46,7 +46,7 @@ pub fn constant_time_copy(v int, mut x []byte, y []byte) {
|
||||
|
||||
// constant_time_less_or_eq returns 1 if x <= y, and 0 otherwise.
|
||||
// it is undefined when x or y are negative, or > (2^32 - 1)
|
||||
pub fn constant_time_less_or_eq(x, y int) int {
|
||||
pub fn constant_time_less_or_eq(x int, y int) int {
|
||||
x32 := int(x)
|
||||
y32 := int(y)
|
||||
return int(((x32 - y32 - 1) >> 31) & 1)
|
||||
|
Reference in New Issue
Block a user