Skip to content
Permalink
Browse files

Fix golint warnings (#422)

* Add documentation comments

golint now requires all exported types, methods, and constants to
have documentation comments on them. And the comments should have
a particular style, starting with the identifier they describe.

* Unexport implementation details

These constants should not be exported, they are for internal use.
Spell them with a lowercase initial letter instead of uppercase.

* Replace snake_case with camelCase

Go code style requires to use camelCase for variables, not snake_case.

* Spell ID as "ID", not "Id"

golint warns us about incorrect spelling, fix it where possible.

Don't rename GetRemoteId and GetPublicKeyForId methods to avoid
breaking backward compatibility.

* Drop explicit zero initialization

Values are zero-initialized by default, golint warns about explicit
zero initialization. Remove it.
  • Loading branch information...
ilammy committed Mar 12, 2019
1 parent 5b5c9a0 commit 9ab951e3fc87f16152e46e0f19166198b572209f
@@ -15,7 +15,7 @@ import (
"strings"
)

func send_message(message []byte, endpoint string) ([]byte, error) {
func sendMessage(message []byte, endpoint string) ([]byte, error) {
values := url.Values{}
values.Add("message", base64.StdEncoding.EncodeToString(message))
request, err := http.NewRequest("POST", endpoint, bytes.NewBufferString(values.Encode()))
@@ -39,32 +39,32 @@ func send_message(message []byte, endpoint string) ([]byte, error) {
}

func main() {
input_buffer := bufio.NewReader(os.Stdin)
inputBuffer := bufio.NewReader(os.Stdin)
fmt.Println("Type your settings from https://themis.cossacklabs.com/interactive-simulator/setup/")

fmt.Println("JSON endpoint: ")
endpoint, err := input_buffer.ReadString('\n')
endpoint, err := inputBuffer.ReadString('\n')
endpoint = strings.TrimRight(endpoint, "\n\r")

fmt.Println("Your private key in base64 format:")
client_private, err := input_buffer.ReadBytes('\n')
client_private, err = base64.StdEncoding.DecodeString(string(client_private))
clientPrivate, err := inputBuffer.ReadBytes('\n')
clientPrivate, err = base64.StdEncoding.DecodeString(string(clientPrivate))
if err != nil {
fmt.Println("Incorrect base64 format for private key")
return
}

fmt.Println("Server public key in base64 format:")
server_public, err := input_buffer.ReadBytes('\n')
server_public = bytes.TrimRight(server_public, "\r\n")
server_public, err = base64.StdEncoding.DecodeString(string(server_public))
secure_message := message.New(
&keys.PrivateKey{bytes.TrimRight(client_private, "\r\n")},
&keys.PublicKey{server_public})
serverPublic, err := inputBuffer.ReadBytes('\n')
serverPublic = bytes.TrimRight(serverPublic, "\r\n")
serverPublic, err = base64.StdEncoding.DecodeString(string(serverPublic))
secureMessage := message.New(
&keys.PrivateKey{bytes.TrimRight(clientPrivate, "\r\n")},
&keys.PublicKey{serverPublic})

for {
fmt.Println("Print message to send (or quit to stop):")
line, _, err := input_buffer.ReadLine()
line, _, err := inputBuffer.ReadLine()
if err != nil {
fmt.Println(err)
return
@@ -73,17 +73,17 @@ func main() {
return
}

wrapped, err := secure_message.Wrap(line)
wrapped, err := secureMessage.Wrap(line)
if err != nil {
fmt.Println("Error in wraping", err)
return
}
data, err := send_message(wrapped, endpoint)
data, err := sendMessage(wrapped, endpoint)
if err != nil {
fmt.Println("Error occurred:", err)
return
}
unwrapped, err := secure_message.Unwrap(data)
unwrapped, err := secureMessage.Unwrap(data)
fmt.Println(string(unwrapped))
}
}
@@ -15,24 +15,24 @@ import (
"strings"
)

type client_transport_callback struct {
server_public []byte
server_id []byte
type clientTransportCallback struct {
serverPublic []byte
serverID []byte
}

func (clb *client_transport_callback) GetPublicKeyForId(ss *session.SecureSession, id []byte) *keys.PublicKey {
if bytes.Equal(id, clb.server_id) {
return &keys.PublicKey{clb.server_public}
func (clb *clientTransportCallback) GetPublicKeyForId(ss *session.SecureSession, id []byte) *keys.PublicKey {
if bytes.Equal(id, clb.serverID) {
return &keys.PublicKey{clb.serverPublic}
}
return nil

}

func (clb *client_transport_callback) StateChanged(ss *session.SecureSession, state int) {
func (clb *clientTransportCallback) StateChanged(ss *session.SecureSession, state int) {

}

func send_message(message []byte, endpoint string) ([]byte, error) {
func sendMessage(message []byte, endpoint string) ([]byte, error) {
values := url.Values{}
values.Add("message", base64.StdEncoding.EncodeToString(message))
request, err := http.NewRequest("POST", endpoint, bytes.NewBufferString(values.Encode()))
@@ -57,21 +57,21 @@ func send_message(message []byte, endpoint string) ([]byte, error) {
}

func clientService(client *session.SecureSession, ch chan []byte, finCh chan int) {
connection_request, err := client.ConnectRequest()
connectionRequest, err := client.ConnectRequest()
if nil != err {
return
}

ch <- connection_request
ch <- connectionRequest
for {
buf := <-ch

buf, is_negotiation, err := client.Unwrap(buf)
buf, isNegotiation, err := client.Unwrap(buf)
if nil != err {
return
}

if is_negotiation {
if isNegotiation {
ch <- buf
continue
}
@@ -82,81 +82,81 @@ func clientService(client *session.SecureSession, ch chan []byte, finCh chan int
}

func main() {
input_buffer := bufio.NewReader(os.Stdin)
inputBuffer := bufio.NewReader(os.Stdin)
fmt.Println("Type your settings from https://themis.cossacklabs.com/interactive-simulator/setup/")

fmt.Println("JSON endpoint: ")
endpoint, err := input_buffer.ReadString('\n')
endpoint, err := inputBuffer.ReadString('\n')
endpoint = strings.TrimRight(endpoint, "\n\r")

fmt.Println("Your private key in base64 format:")
client_private, err := input_buffer.ReadBytes('\n')
client_private, err = base64.StdEncoding.DecodeString(string(client_private))
clientPrivate, err := inputBuffer.ReadBytes('\n')
clientPrivate, err = base64.StdEncoding.DecodeString(string(clientPrivate))
if err != nil {
fmt.Println("Incorrect base64 format for private key")
return
}

fmt.Println("User_id:")
client_id, err := input_buffer.ReadBytes('\n')
clientID, err := inputBuffer.ReadBytes('\n')

fmt.Println("Server_id:")
server_id, err := input_buffer.ReadBytes('\n')
serverID, err := inputBuffer.ReadBytes('\n')

fmt.Println("Server public key in base64 format:")
server_public, err := input_buffer.ReadBytes('\n')
server_public, err = base64.StdEncoding.DecodeString(string(server_public))
serverPublic, err := inputBuffer.ReadBytes('\n')
serverPublic, err = base64.StdEncoding.DecodeString(string(serverPublic))
// init callback structure
cb := client_transport_callback{
server_public,
bytes.TrimRight(server_id, "\r\n")}
cb := clientTransportCallback{
serverPublic,
bytes.TrimRight(serverID, "\r\n")}

// create session object
client_session, err := session.New(
bytes.TrimRight(client_id, "\r\n"),
&keys.PrivateKey{bytes.TrimRight(client_private, "\r\n")},
clientSession, err := session.New(
bytes.TrimRight(clientID, "\r\n"),
&keys.PrivateKey{bytes.TrimRight(clientPrivate, "\r\n")},
&cb)
if err != nil {
fmt.Println("Session creation error")
return
}

ch := make(chan []byte)
quit_channel := make(chan int)
go clientService(client_session, ch, quit_channel)
is_established := false
quitChannel := make(chan int)
go clientService(clientSession, ch, quitChannel)
isEstablished := false
fmt.Println("Initialize session")
for !is_established {
for !isEstablished {
select {
case data := <-ch:
data, err := send_message(data, endpoint)
data, err := sendMessage(data, endpoint)
if err != nil {
fmt.Println("Error -", err)
return
}
ch <- data
case <-quit_channel:
is_established = true
case <-quitChannel:
isEstablished = true
}
}
fmt.Println("Session established")
for {
fmt.Println("Print message to send (or quit to stop):")
line, _, err := input_buffer.ReadLine()
line, _, err := inputBuffer.ReadLine()
if err != nil {
fmt.Println(err)
return
}
if bytes.Equal(line, []byte("quit")) {
return
}
wrapped, err := client_session.Wrap(line)
data, err := send_message(wrapped, endpoint)
wrapped, err := clientSession.Wrap(line)
data, err := sendMessage(wrapped, endpoint)
if err != nil {
fmt.Println("Error occurred:", err)
return
}
unwrapped, _, err := client_session.Unwrap(data)
unwrapped, _, err := clientSession.Unwrap(data)
fmt.Println(string(unwrapped))
}
}
@@ -21,12 +21,12 @@ func main() {
}
fmt.Println(base64.StdEncoding.EncodeToString(encData))
} else if "dec" == os.Args[1] {
decoded_message, err := base64.StdEncoding.DecodeString(os.Args[3])
decodedMessage, err := base64.StdEncoding.DecodeString(os.Args[3])
if nil != err {
fmt.Println("error decoding message")
return
}
decData, err := sc.Unprotect(decoded_message, nil, []byte(os.Args[4]))
decData, err := sc.Unprotect(decodedMessage, nil, []byte(os.Args[4]))
if nil != err {
fmt.Println("error decrypting message")
return
@@ -21,12 +21,12 @@ func main() {
}
fmt.Println(base64.StdEncoding.EncodeToString(encData))
} else if "dec" == os.Args[1] {
decoded_message, err := base64.StdEncoding.DecodeString(os.Args[3])
decodedMessage, err := base64.StdEncoding.DecodeString(os.Args[3])
if nil != err {
fmt.Println("error decoding message")
return
}
decData, err := sc.Unprotect(decoded_message, nil, nil)
decData, err := sc.Unprotect(decodedMessage, nil, nil)
if nil != err {
fmt.Println("error decrypting message")
return
@@ -26,17 +26,17 @@ func main() {
fmt.Println("token not set")
return
}
decoded_message, err := base64.StdEncoding.DecodeString(os.Args[3])
decodedMessage, err := base64.StdEncoding.DecodeString(os.Args[3])
if nil != err {
fmt.Println("error decoding message")
return
}
decoded_token, err := base64.StdEncoding.DecodeString(os.Args[4])
decodedToken, err := base64.StdEncoding.DecodeString(os.Args[4])
if nil != err {
fmt.Println("error decoding token")
return
}
decData, err := sc.Unprotect(decoded_message, decoded_token, nil)
decData, err := sc.Unprotect(decodedMessage, decodedToken, nil)
if nil != err {
fmt.Println("error decrypting message")
return
@@ -50,12 +50,12 @@ func main() {

if compare.COMPARE_NOT_READY == res {
buf = make([]byte, 10240)
readed_bytes, err := conn.Read(buf)
readBytes, err := conn.Read(buf)
if err != nil {
fmt.Println("error reading bytes from socket")
return
}
buffer, err := sc.Proceed(buf[:readed_bytes])
buffer, err := sc.Proceed(buf[:readBytes])
if nil != err {
fmt.Println("error unwraping message")
return
@@ -27,12 +27,12 @@ func connectionHandler(c net.Conn, secret string) {

if compare.COMPARE_NOT_READY == res {
buf := make([]byte, 10240)
readed_bytes, err := c.Read(buf)
readBytes, err := c.Read(buf)
if err != nil {
fmt.Println("error reading bytes from socket")
return
}
buf, err = sc.Proceed(buf[:readed_bytes])
buf, err = sc.Proceed(buf[:readBytes])
if nil != err {
fmt.Println("error proceeding message")
return
@@ -7,12 +7,12 @@ import (
)

func main() {
key_pair, err := keys.New(keys.KEYTYPE_EC)
keyPair, err := keys.New(keys.KEYTYPE_EC)
if nil != err {
fmt.Println("Keypair generating error")
return
}
fmt.Println(base64.StdEncoding.EncodeToString(key_pair.Private.Value))
fmt.Println(base64.StdEncoding.EncodeToString(key_pair.Public.Value))
fmt.Println(base64.StdEncoding.EncodeToString(keyPair.Private.Value))
fmt.Println(base64.StdEncoding.EncodeToString(keyPair.Public.Value))
return
}
@@ -13,18 +13,18 @@ func main() {
fmt.Printf("usage: %s <command> <private key> <peer public key> <message>\n", os.Args[0])
return
}
decoded_key, err := base64.StdEncoding.DecodeString(os.Args[2])
decodedKey, err := base64.StdEncoding.DecodeString(os.Args[2])
if nil != err {
fmt.Println("error decoding private key")
return
}
pr := keys.PrivateKey{decoded_key}
decoded_key, err = base64.StdEncoding.DecodeString(os.Args[3])
pr := keys.PrivateKey{decodedKey}
decodedKey, err = base64.StdEncoding.DecodeString(os.Args[3])
if nil != err {
fmt.Println("error decoding private key")
return
}
pu := keys.PublicKey{decoded_key}
pu := keys.PublicKey{decodedKey}
sm := message.New(&pr, &pu)
if "enc" == os.Args[1] {
wrapped, err := sm.Wrap([]byte(os.Args[4]))
@@ -34,12 +34,12 @@ func main() {
}
fmt.Println(base64.StdEncoding.EncodeToString(wrapped))
} else if "dec" == os.Args[1] {
decoded_message, err := base64.StdEncoding.DecodeString(os.Args[4])
decodedMessage, err := base64.StdEncoding.DecodeString(os.Args[4])
if nil != err {
fmt.Println("error decoding message")
return
}
unwrapped, err := sm.Unwrap(decoded_message)
unwrapped, err := sm.Unwrap(decodedMessage)
if nil != err {
fmt.Println("error decrypting message")
return
Oops, something went wrong.

0 comments on commit 9ab951e

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.