X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcypherpunks.ru%2Fgovpn%2Fegd.go;h=f54c1168d11e0ce4287090e0079678414443316a;hb=f47fff1e42f75b736e7067ec06c2e81394833d46;hp=04ec87b9678cf2dfa10c576c84bfc66bbe4ef493;hpb=a87ec543051d428aaa3888804d6c8451f6d537c9;p=govpn.git diff --git a/src/cypherpunks.ru/govpn/egd.go b/src/cypherpunks.ru/govpn/egd.go index 04ec87b..f54c116 100644 --- a/src/cypherpunks.ru/govpn/egd.go +++ b/src/cypherpunks.ru/govpn/egd.go @@ -1,6 +1,6 @@ /* GoVPN -- simple secure free software virtual private network daemon -Copyright (C) 2014-2016 Sergey Matveev +Copyright (C) 2014-2017 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,13 +20,12 @@ package govpn import ( "crypto/rand" - "errors" "io" "net" ) var ( - Rand io.Reader = rand.Reader + Rand = rand.Reader ) type EGDRand string @@ -37,18 +36,9 @@ func (egdPath EGDRand) Read(b []byte) (int, error) { if err != nil { return 0, err } + defer conn.Close() conn.Write([]byte{0x02, byte(len(b))}) - read, err := conn.Read(b) - if err != nil { - conn.Close() - return read, err - } - if read != len(b) { - conn.Close() - return read, errors.New("Got less bytes than expected from EGD") - } - conn.Close() - return read, nil + return io.ReadFull(conn, b) } func EGDInit(path string) {