remove bytes.Copy
replace all calls with calls to copy use copy in regexp and bytes.Buffer R=rsc CC=golang-dev https://golang.org/cl/157073
This commit is contained in:
джерело
d1f931a694
коміт
a1e7e65e2d
@ -4,10 +4,6 @@
|
|||||||
|
|
||||||
package tls
|
package tls
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes";
|
|
||||||
)
|
|
||||||
|
|
||||||
type clientHelloMsg struct {
|
type clientHelloMsg struct {
|
||||||
raw []byte;
|
raw []byte;
|
||||||
major, minor uint8;
|
major, minor uint8;
|
||||||
@ -30,9 +26,9 @@ func (m *clientHelloMsg) marshal() []byte {
|
|||||||
x[3] = uint8(length);
|
x[3] = uint8(length);
|
||||||
x[4] = m.major;
|
x[4] = m.major;
|
||||||
x[5] = m.minor;
|
x[5] = m.minor;
|
||||||
bytes.Copy(x[6:38], m.random);
|
copy(x[6:38], m.random);
|
||||||
x[38] = uint8(len(m.sessionId));
|
x[38] = uint8(len(m.sessionId));
|
||||||
bytes.Copy(x[39:39+len(m.sessionId)], m.sessionId);
|
copy(x[39:39+len(m.sessionId)], m.sessionId);
|
||||||
y := x[39+len(m.sessionId) : len(x)];
|
y := x[39+len(m.sessionId) : len(x)];
|
||||||
y[0] = uint8(len(m.cipherSuites) >> 7);
|
y[0] = uint8(len(m.cipherSuites) >> 7);
|
||||||
y[1] = uint8(len(m.cipherSuites) << 1);
|
y[1] = uint8(len(m.cipherSuites) << 1);
|
||||||
@ -42,7 +38,7 @@ func (m *clientHelloMsg) marshal() []byte {
|
|||||||
}
|
}
|
||||||
z := y[2+len(m.cipherSuites)*2 : len(y)];
|
z := y[2+len(m.cipherSuites)*2 : len(y)];
|
||||||
z[0] = uint8(len(m.compressionMethods));
|
z[0] = uint8(len(m.compressionMethods));
|
||||||
bytes.Copy(z[1:len(z)], m.compressionMethods);
|
copy(z[1:len(z)], m.compressionMethods);
|
||||||
m.raw = x;
|
m.raw = x;
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
@ -112,9 +108,9 @@ func (m *serverHelloMsg) marshal() []byte {
|
|||||||
x[3] = uint8(length);
|
x[3] = uint8(length);
|
||||||
x[4] = m.major;
|
x[4] = m.major;
|
||||||
x[5] = m.minor;
|
x[5] = m.minor;
|
||||||
bytes.Copy(x[6:38], m.random);
|
copy(x[6:38], m.random);
|
||||||
x[38] = uint8(len(m.sessionId));
|
x[38] = uint8(len(m.sessionId));
|
||||||
bytes.Copy(x[39:39+len(m.sessionId)], m.sessionId);
|
copy(x[39:39+len(m.sessionId)], m.sessionId);
|
||||||
z := x[39+len(m.sessionId) : len(x)];
|
z := x[39+len(m.sessionId) : len(x)];
|
||||||
z[0] = uint8(m.cipherSuite >> 8);
|
z[0] = uint8(m.cipherSuite >> 8);
|
||||||
z[1] = uint8(m.cipherSuite);
|
z[1] = uint8(m.cipherSuite);
|
||||||
@ -156,7 +152,7 @@ func (m *certificateMsg) marshal() (x []byte) {
|
|||||||
y[0] = uint8(len(slice) >> 16);
|
y[0] = uint8(len(slice) >> 16);
|
||||||
y[1] = uint8(len(slice) >> 8);
|
y[1] = uint8(len(slice) >> 8);
|
||||||
y[2] = uint8(len(slice));
|
y[2] = uint8(len(slice));
|
||||||
bytes.Copy(y[3:len(y)], slice);
|
copy(y[3:len(y)], slice);
|
||||||
y = y[3+len(slice) : len(y)];
|
y = y[3+len(slice) : len(y)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,7 +185,7 @@ func (m *clientKeyExchangeMsg) marshal() []byte {
|
|||||||
x[3] = uint8(length);
|
x[3] = uint8(length);
|
||||||
x[4] = uint8(len(m.ciphertext) >> 8);
|
x[4] = uint8(len(m.ciphertext) >> 8);
|
||||||
x[5] = uint8(len(m.ciphertext));
|
x[5] = uint8(len(m.ciphertext));
|
||||||
bytes.Copy(x[6:len(x)], m.ciphertext);
|
copy(x[6:len(x)], m.ciphertext);
|
||||||
|
|
||||||
m.raw = x;
|
m.raw = x;
|
||||||
return x;
|
return x;
|
||||||
@ -221,7 +217,7 @@ func (m *finishedMsg) marshal() (x []byte) {
|
|||||||
x = make([]byte, 16);
|
x = make([]byte, 16);
|
||||||
x[0] = typeFinished;
|
x[0] = typeFinished;
|
||||||
x[3] = 12;
|
x[3] = 12;
|
||||||
bytes.Copy(x[4:len(x)], m.verifyData);
|
copy(x[4:len(x)], m.verifyData);
|
||||||
m.raw = x;
|
m.raw = x;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
19
prf.go
19
prf.go
@ -5,7 +5,6 @@
|
|||||||
package tls
|
package tls
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes";
|
|
||||||
"crypto/hmac";
|
"crypto/hmac";
|
||||||
"crypto/md5";
|
"crypto/md5";
|
||||||
"crypto/sha1";
|
"crypto/sha1";
|
||||||
@ -37,7 +36,7 @@ func pHash(result, secret, seed []byte, hash hash.Hash) {
|
|||||||
if j+todo > len(result) {
|
if j+todo > len(result) {
|
||||||
todo = len(result) - j
|
todo = len(result) - j
|
||||||
}
|
}
|
||||||
bytes.Copy(result[j:j+todo], b);
|
copy(result[j:j+todo], b);
|
||||||
j += todo;
|
j += todo;
|
||||||
|
|
||||||
h.Reset();
|
h.Reset();
|
||||||
@ -52,8 +51,8 @@ func pRF11(result, secret, label, seed []byte) {
|
|||||||
hashMD5 := md5.New();
|
hashMD5 := md5.New();
|
||||||
|
|
||||||
labelAndSeed := make([]byte, len(label)+len(seed));
|
labelAndSeed := make([]byte, len(label)+len(seed));
|
||||||
bytes.Copy(labelAndSeed, label);
|
copy(labelAndSeed, label);
|
||||||
bytes.Copy(labelAndSeed[len(label):len(labelAndSeed)], seed);
|
copy(labelAndSeed[len(label):len(labelAndSeed)], seed);
|
||||||
|
|
||||||
s1, s2 := splitPreMasterSecret(secret);
|
s1, s2 := splitPreMasterSecret(secret);
|
||||||
pHash(result, s1, labelAndSeed, hashMD5);
|
pHash(result, s1, labelAndSeed, hashMD5);
|
||||||
@ -81,13 +80,13 @@ var serverFinishedLabel = strings.Bytes("server finished")
|
|||||||
// 4346, section 6.3.
|
// 4346, section 6.3.
|
||||||
func keysFromPreMasterSecret11(preMasterSecret, clientRandom, serverRandom []byte, macLen, keyLen int) (masterSecret, clientMAC, serverMAC, clientKey, serverKey []byte) {
|
func keysFromPreMasterSecret11(preMasterSecret, clientRandom, serverRandom []byte, macLen, keyLen int) (masterSecret, clientMAC, serverMAC, clientKey, serverKey []byte) {
|
||||||
var seed [tlsRandomLength * 2]byte;
|
var seed [tlsRandomLength * 2]byte;
|
||||||
bytes.Copy(seed[0:len(clientRandom)], clientRandom);
|
copy(seed[0:len(clientRandom)], clientRandom);
|
||||||
bytes.Copy(seed[len(clientRandom):len(seed)], serverRandom);
|
copy(seed[len(clientRandom):len(seed)], serverRandom);
|
||||||
masterSecret = make([]byte, masterSecretLength);
|
masterSecret = make([]byte, masterSecretLength);
|
||||||
pRF11(masterSecret, preMasterSecret, masterSecretLabel, seed[0:len(seed)]);
|
pRF11(masterSecret, preMasterSecret, masterSecretLabel, seed[0:len(seed)]);
|
||||||
|
|
||||||
bytes.Copy(seed[0:len(clientRandom)], serverRandom);
|
copy(seed[0:len(clientRandom)], serverRandom);
|
||||||
bytes.Copy(seed[len(serverRandom):len(seed)], clientRandom);
|
copy(seed[len(serverRandom):len(seed)], clientRandom);
|
||||||
|
|
||||||
n := 2*macLen + 2*keyLen;
|
n := 2*macLen + 2*keyLen;
|
||||||
keyMaterial := make([]byte, n);
|
keyMaterial := make([]byte, n);
|
||||||
@ -124,8 +123,8 @@ func (h finishedHash) Write(msg []byte) (n int, err os.Error) {
|
|||||||
// message given the MD5 and SHA1 hashes of a set of handshake messages.
|
// message given the MD5 and SHA1 hashes of a set of handshake messages.
|
||||||
func finishedSum(md5, sha1, label, masterSecret []byte) []byte {
|
func finishedSum(md5, sha1, label, masterSecret []byte) []byte {
|
||||||
seed := make([]byte, len(md5)+len(sha1));
|
seed := make([]byte, len(md5)+len(sha1));
|
||||||
bytes.Copy(seed, md5);
|
copy(seed, md5);
|
||||||
bytes.Copy(seed[len(md5):len(seed)], sha1);
|
copy(seed[len(md5):len(seed)], sha1);
|
||||||
out := make([]byte, finishedVerifyLength);
|
out := make([]byte, finishedVerifyLength);
|
||||||
pRF11(out, masterSecret, label, seed);
|
pRF11(out, masterSecret, label, seed);
|
||||||
return out;
|
return out;
|
||||||
|
@ -10,7 +10,6 @@ package tls
|
|||||||
// state, or for a notification when the state changes.
|
// state, or for a notification when the state changes.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes";
|
|
||||||
"container/list";
|
"container/list";
|
||||||
"crypto/subtle";
|
"crypto/subtle";
|
||||||
"hash";
|
"hash";
|
||||||
@ -228,8 +227,8 @@ func (p *recordProcessor) processHandshakeRecord(data []byte) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
newBuf := make([]byte, len(p.handshakeBuf)+len(data));
|
newBuf := make([]byte, len(p.handshakeBuf)+len(data));
|
||||||
bytes.Copy(newBuf, p.handshakeBuf);
|
copy(newBuf, p.handshakeBuf);
|
||||||
bytes.Copy(newBuf[len(p.handshakeBuf):len(newBuf)], data);
|
copy(newBuf[len(p.handshakeBuf):len(newBuf)], data);
|
||||||
p.handshakeBuf = newBuf;
|
p.handshakeBuf = newBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
tls.go
3
tls.go
@ -6,7 +6,6 @@
|
|||||||
package tls
|
package tls
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes";
|
|
||||||
"io";
|
"io";
|
||||||
"os";
|
"os";
|
||||||
"net";
|
"net";
|
||||||
@ -59,7 +58,7 @@ func (tls *Conn) Read(p []byte) (int, os.Error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
n := bytes.Copy(p, tls.readBuf);
|
n := copy(p, tls.readBuf);
|
||||||
tls.readBuf = tls.readBuf[n:len(tls.readBuf)];
|
tls.readBuf = tls.readBuf[n:len(tls.readBuf)];
|
||||||
return n, nil;
|
return n, nil;
|
||||||
}
|
}
|
||||||
|
Завантаження…
Посилання в новій задачі
Block a user