mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
urllib: rem underscore methods from; add strings index_bytes
This commit is contained in:
committed by
Alexander Medvednikov
parent
f3abb9e682
commit
f8fefd5a60
@@ -26,7 +26,8 @@ mut:
|
||||
tmp []byte
|
||||
}
|
||||
|
||||
fn _new_cbc(b AesCipher, iv []byte) AesCbc {
|
||||
// internal
|
||||
fn new_aes_cbc(b AesCipher, iv []byte) AesCbc {
|
||||
return AesCbc{
|
||||
b: b,
|
||||
block_size: b.block_size(),
|
||||
@@ -42,7 +43,7 @@ pub fn new_cbc(b AesCipher, iv []byte) AesCbc {
|
||||
if iv.len != b.block_size() {
|
||||
panic('crypto.cipher.new_cbc_encrypter: IV length must equal block size')
|
||||
}
|
||||
return _new_cbc(b, iv)
|
||||
return new_aes_cbc(b, iv)
|
||||
}
|
||||
|
||||
pub fn (x &AesCbc) block_size() int { return x.block_size }
|
||||
|
||||
@@ -26,22 +26,22 @@ pub fn read(bytes_needed int) ?[]byte {
|
||||
if bytes_needed > ReadBatchSize {
|
||||
no_batches := int(math.floor(f64(bytes_needed/ReadBatchSize)))
|
||||
for i:=0; i<no_batches; i++ {
|
||||
if _getrandom(ReadBatchSize, buffer+bytes_read) == -1 {
|
||||
if getrandom(ReadBatchSize, buffer+bytes_read) == -1 {
|
||||
return ReadError
|
||||
}
|
||||
bytes_read += ReadBatchSize
|
||||
}
|
||||
}
|
||||
if _getrandom(bytes_needed-bytes_read, buffer+bytes_read) == -1 {
|
||||
if getrandom(bytes_needed-bytes_read, buffer+bytes_read) == -1 {
|
||||
return ReadError
|
||||
}
|
||||
|
||||
return c_array_to_bytes_tmp(bytes_needed, buffer)
|
||||
}
|
||||
|
||||
fn _getrandom(bytes_needed int, buffer voidptr) int {
|
||||
fn getrandom(bytes_needed int, buffer voidptr) int {
|
||||
if bytes_needed > ReadBatchSize {
|
||||
panic('_getrandom() dont request more thane $ReadBatchSize bytes at once.')
|
||||
panic('getrandom() dont request more thane $ReadBatchSize bytes at once.')
|
||||
}
|
||||
return C.syscall(C.SYS_getrandom, buffer, bytes_needed, 0)
|
||||
}
|
||||
|
||||
@@ -120,7 +120,8 @@ fn (d mut Digest) reset() {
|
||||
d.len = 0
|
||||
}
|
||||
|
||||
fn _new(hash crypto.Hash) &Digest {
|
||||
// internal
|
||||
fn new_digest(hash crypto.Hash) &Digest {
|
||||
mut d := &Digest{function: hash}
|
||||
d.reset()
|
||||
return d
|
||||
@@ -128,22 +129,22 @@ fn _new(hash crypto.Hash) &Digest {
|
||||
|
||||
// new returns a new Digest (implementing hash.Hash) computing the SHA-512 checksum.
|
||||
pub fn new() &Digest {
|
||||
return _new(crypto.Hash.SHA512)
|
||||
return new_digest(crypto.Hash.SHA512)
|
||||
}
|
||||
|
||||
// new512_224 returns a new Digest (implementing hash.Hash) computing the SHA-512/224 checksum.
|
||||
fn new512_224() &Digest {
|
||||
return _new(crypto.Hash.SHA512_224)
|
||||
return new_digest(crypto.Hash.SHA512_224)
|
||||
}
|
||||
|
||||
// new512_256 returns a new Digest (implementing hash.Hash) computing the SHA-512/256 checksum.
|
||||
fn new512_256() &Digest {
|
||||
return _new(crypto.Hash.SHA512_256)
|
||||
return new_digest(crypto.Hash.SHA512_256)
|
||||
}
|
||||
|
||||
// new384 returns a new Digest (implementing hash.Hash) computing the SHA-384 checksum.
|
||||
fn new384() &Digest {
|
||||
return _new(crypto.Hash.SHA384)
|
||||
return new_digest(crypto.Hash.SHA384)
|
||||
}
|
||||
|
||||
fn (d mut Digest) write(p_ []byte) ?int {
|
||||
@@ -245,14 +246,14 @@ fn (d mut Digest) checksum() []byte {
|
||||
|
||||
// sum512 returns the SHA512 checksum of the data.
|
||||
pub fn sum512(data []byte) []byte {
|
||||
mut d := _new(crypto.Hash.SHA512)
|
||||
mut d := new_digest(crypto.Hash.SHA512)
|
||||
d.write(data)
|
||||
return d.checksum()
|
||||
}
|
||||
|
||||
// sum384 returns the SHA384 checksum of the data.
|
||||
pub fn sum384(data []byte) []byte {
|
||||
mut d := _new(crypto.Hash.SHA384)
|
||||
mut d := new_digest(crypto.Hash.SHA384)
|
||||
d.write(data)
|
||||
sum := d.checksum()
|
||||
mut sum384 := [byte(0)].repeat(Size384)
|
||||
@@ -262,7 +263,7 @@ pub fn sum384(data []byte) []byte {
|
||||
|
||||
// sum512_224 returns the Sum512/224 checksum of the data.
|
||||
pub fn sum512_224(data []byte) []byte {
|
||||
mut d := _new(crypto.Hash.SHA512_224)
|
||||
mut d := new_digest(crypto.Hash.SHA512_224)
|
||||
d.write(data)
|
||||
sum := d.checksum()
|
||||
mut sum224 := [byte(0)].repeat(Size224)
|
||||
@@ -272,7 +273,7 @@ pub fn sum512_224(data []byte) []byte {
|
||||
|
||||
// Sum512_256 returns the Sum512/256 checksum of the data.
|
||||
pub fn sum512_256(data []byte) []byte {
|
||||
mut d := _new(crypto.Hash.SHA512_256)
|
||||
mut d := new_digest(crypto.Hash.SHA512_256)
|
||||
d.write(data)
|
||||
sum := d.checksum()
|
||||
mut sum256 := [byte(0)].repeat(Size256)
|
||||
|
||||
Reference in New Issue
Block a user