[tor-commits] [goptlib/master] Factor out the reading and validation from readAuthCookieFile.
dcf at torproject.org
dcf at torproject.org
Sun Nov 10 03:11:28 UTC 2013
commit e68e6610007a3fcd388c2a93d7e13dbd31ff4d09
Author: David Fifield <david at bamsoftware.com>
Date: Sat Nov 9 16:37:55 2013 -0800
Factor out the reading and validation from readAuthCookieFile.
To facilitatate tests that don't need an actual file with a name.
---
pt.go | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/pt.go b/pt.go
index b79f08b..28c8639 100644
--- a/pt.go
+++ b/pt.go
@@ -321,19 +321,11 @@ func getServerBindAddrs(methodNames []string) ([]BindAddr, error) {
return result, nil
}
-// Read and validate the contents of an auth cookie file. Returns the 32-byte
-// cookie. See section 4.2.1.2 of pt-spec.txt.
-func readAuthCookieFile(filename string) ([]byte, error) {
+func readAuthCookie(f io.Reader) ([]byte, error) {
authCookieHeader := []byte("! Extended ORPort Auth Cookie !\x0a")
header := make([]byte, 32)
cookie := make([]byte, 32)
- f, err := os.Open(filename)
- if err != nil {
- return cookie, err
- }
- defer f.Close()
-
n, err := io.ReadFull(f, header)
if err != nil {
return cookie, err
@@ -357,6 +349,18 @@ func readAuthCookieFile(filename string) ([]byte, error) {
return cookie, nil
}
+// Read and validate the contents of an auth cookie file. Returns the 32-byte
+// cookie. See section 4.2.1.2 of pt-spec.txt.
+func readAuthCookieFile(filename string) ([]byte, error) {
+ f, err := os.Open(filename)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+
+ return readAuthCookie(f)
+}
+
// This structure is returned by ServerSetup. It consists of a list of
// BindAddrs, an address for the ORPort, an address for the extended ORPort (if
// any), and an authentication cookie (if any).
More information about the tor-commits
mailing list