1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vfmt: change all '$expr' to '${expr}' (#16428)

This commit is contained in:
yuyi
2022-11-15 21:53:13 +08:00
committed by GitHub
parent 56239b4a23
commit 017ace6ea7
859 changed files with 7156 additions and 7135 deletions

View File

@@ -23,7 +23,7 @@ import crypto.rand
fn main() {
// remember to save this key somewhere if you ever want to decrypt your data
key := rand.bytes(32)!
println('KEY: $key')
println('KEY: ${key}')
// this data is one block (16 bytes) big
mut data := 'THIS IS THE DATA'.bytes()
@@ -70,17 +70,17 @@ fn main() {
token := make_token(secret)
ok := auth_verify(secret, token)
dt := sw.elapsed().microseconds()
println('token: $token')
println('auth_verify(secret, token): $ok')
println('Elapsed time: $dt uS')
println('token: ${token}')
println('auth_verify(secret, token): ${ok}')
println('Elapsed time: ${dt} uS')
}
fn make_token(secret string) string {
header := base64.url_encode(json.encode(JwtHeader{'HS256', 'JWT'}).bytes())
payload := base64.url_encode(json.encode(JwtPayload{'1234567890', 'John Doe', 1516239022}).bytes())
signature := base64.url_encode(hmac.new(secret.bytes(), '${header}.$payload'.bytes(),
signature := base64.url_encode(hmac.new(secret.bytes(), '${header}.${payload}'.bytes(),
sha256.sum, sha256.block_size))
jwt := '${header}.${payload}.$signature'
jwt := '${header}.${payload}.${signature}'
return jwt
}

View File

@@ -32,14 +32,14 @@ const magic_cipher_data = [u8(0x4f), 0x72, 0x70, 0x68, 0x65, 0x61, 0x6e, 0x42, 0
// generate_from_password return a bcrypt string from Hashed struct.
pub fn generate_from_password(password []u8, cost int) ?string {
mut p := new_from_password(password, cost) or { return error('Error: $err') }
mut p := new_from_password(password, cost) or { return error('Error: ${err}') }
x := p.hash_u8()
return x.bytestr()
}
// compare_hash_and_password compares a bcrypt hashed password with its possible hashed version.
pub fn compare_hash_and_password(password []u8, hashed_password []u8) ? {
mut p := new_from_hash(hashed_password) or { return error('Error: $err') }
mut p := new_from_hash(hashed_password) or { return error('Error: ${err}') }
p.salt << `=`
p.salt << `=`
other_hash := bcrypt(password, p.cost, p.salt) or { return error('err') }
@@ -169,7 +169,7 @@ fn (mut h Hashed) decode_version(sbytes []u8) ?int {
return error("bcrypt hashes must start with '$'")
}
if sbytes[1] != bcrypt.major_version[0] {
return error('bcrypt algorithm version $bcrypt.major_version')
return error('bcrypt algorithm version ${bcrypt.major_version}')
}
h.major = sbytes[1].ascii_str()
mut n := 3

View File

@@ -68,7 +68,7 @@ pub fn sign(privatekey PrivateKey, message []u8) ![]u8 {
fn sign_generic(mut signature []u8, privatekey []u8, message []u8) ! {
if privatekey.len != ed25519.private_key_size {
panic('ed25519: bad private key length: $privatekey.len')
panic('ed25519: bad private key length: ${privatekey.len}')
}
seed, publickey := privatekey[..ed25519.seed_size], privatekey[ed25519.seed_size..]
@@ -110,7 +110,7 @@ fn sign_generic(mut signature []u8, privatekey []u8, message []u8) ! {
// verify reports whether sig is a valid signature of message by publickey.
pub fn verify(publickey PublicKey, message []u8, sig []u8) !bool {
if publickey.len != ed25519.public_key_size {
return error('ed25519: bad public key length: $publickey.len')
return error('ed25519: bad public key length: ${publickey.len}')
}
if sig.len != ed25519.signature_size || sig[63] & 224 != 0 {
@@ -165,7 +165,7 @@ pub fn new_key_from_seed(seed []u8) PrivateKey {
fn new_key_from_seed_generic(mut privatekey []u8, seed []u8) {
if seed.len != ed25519.seed_size {
panic('ed25519: bad seed length: $seed.len')
panic('ed25519: bad seed length: ${seed.len}')
}
mut h := sha512.sum512(seed)

View File

@@ -15,14 +15,14 @@ fn main() {
sig := ed25519.sign(priv, m)!
println('=== Message ===')
println('Msg: $msg \nHash: $m')
println('Msg: ${msg} \nHash: ${m}')
println('=== Public key ===')
println('Public key (Hex): ${hex.encode(publ)}')
println(' Public key (Base64): ${base64.encode(publ)}')
println('=== Private key ===')
println('Private key: $priv.seed().hex()') // priv[0:32]
println('Private key: ${priv.seed().hex()}') // priv[0:32]
println(' Private key (Base64): ${base64.encode(priv.seed())}') // priv[0:32]
println(' Private key (Base64) Full key: ${base64.encode(priv)}')
println(' Private key (Full key in Hex): ${hex.encode(priv)}')
@@ -34,7 +34,7 @@ fn main() {
rtn := ed25519.verify(publ, m, sig)!
if rtn {
println('Signature verified :$rtn')
println('Signature verified :${rtn}')
} else {
println('signature does not verify :${!rtn}')
}

View File

@@ -33,7 +33,7 @@ pub fn read(bytes_needed int) ![]u8 {
fn getrandom(bytes_needed int, buffer voidptr) int {
if bytes_needed > rand.read_batch_size {
panic('getrandom() dont request more than $rand.read_batch_size bytes at once.')
panic('getrandom() dont request more than ${rand.read_batch_size} bytes at once.')
}
return unsafe { C.syscall(C.SYS_getrandom, buffer, bytes_needed, 0) }
}

View File

@@ -36,7 +36,7 @@ pub fn read(bytes_needed int) ![]u8 {
fn v_getrandom(bytes_needed int, buffer voidptr) int {
if bytes_needed > rand.read_batch_size {
panic('getrandom() dont request more than $rand.read_batch_size bytes at once.')
panic('getrandom() dont request more than ${rand.read_batch_size} bytes at once.')
}
return C.getrandom(buffer, bytes_needed, 0)
}