diff --git a/go.mod b/go.mod index 1305ba80632d68316baa2b69ad6bdea1f5b9d703..7502337a8ac43434738d64ce812b63a8aeff4707 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module go.jolheiser.com/spectre go 1.17 -require golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa +require golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa // indirect diff --git a/go.sum b/go.sum index 49ae2ce2300a7a01d97e71944aff2f5154dfc415..a6458a0dcdeccf5f8262842ce6315924c58d9cd7 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,2 @@ golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa h1:idItI2DDfCokpg0N51B2VtiLdJ4vAuXC9fnCb2gACo4= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/scope.go b/scope.go index 7cd8baa598402c8d09a2ec2833c6234c51ab661f..a23f9362324e252e6f0cbe640021ef93883906db 100644 --- a/scope.go +++ b/scope.go @@ -14,13 +14,13 @@ type Scoper interface { Scope(Scope) string } -// SimpleScoper is a simple Scoper +// SimpleScope is a simple Scoper -type SimpleScoper struct { +type SimpleScope struct { Key string } // Scope fulfills Scoper -func (s SimpleScoper) Scope(scope Scope) string { +func (s SimpleScope) Scope(scope Scope) string { switch scope { case Identification: return s.Key + ".login" @@ -32,8 +32,3 @@ default: return s.Key } } - -// DefaultScoper is the default Scoper -var DefaultScoper = SimpleScoper{ - Key: "com.lyndir.masterpassword", -} diff --git a/spectre.go b/spectre.go index db642df76c33b2e9c482c1e3a84355456999b324..d960726ad92d53e5a6111f9371da8a465ab7714e 100644 --- a/spectre.go +++ b/spectre.go @@ -17,27 +17,14 @@ scoper Scoper } // New returns a Spectre client -func New(name, secret string, opts ...SpectreOption) (s *Spectre, err error) { +func New(name, secret string, scoper Scoper) (s *Spectre, err error) { s = &Spectre{ name: name, secret: secret, - scoper: DefaultScoper, - } - for _, opt := range opts { - opt(s) + scoper: scoper, } s.key, err = s.userKey() return -} - -// SpectreOption is a Spectre option -type SpectreOption func(*Spectre) - -// WithScoper assigns a scoper to Spectre -func WithScoper(scoper Scoper) SpectreOption { - return func(s *Spectre) { - s.scoper = scoper - } } func (s *Spectre) userKey() ([]byte, error) { diff --git a/spectre_test.go b/spectre_test.go index 27deb2ddd0930082c53921851c35b51a36c9e1f9..d164e0a48b4e076737ed770c6178ac10a0b4ca2a 100644 --- a/spectre_test.go +++ b/spectre_test.go @@ -4,6 +4,7 @@ import ( _ "embed" "encoding/xml" "strconv" + "strings" "testing" ) @@ -14,13 +15,16 @@ t.Log("could not load test data") t.FailNow() } + scoper := SimpleScope{ + Key: "com.lyndir.masterpassword", + } dc := tests.Cases[0] for _, tc := range tests.Cases[1:] { t.Run(tc.ID, func(t *testing.T) { user := def(dc.UserName, tc.UserName) secret := def(dc.UserSecret, tc.UserSecret) - s, err := New(user, secret) + s, err := New(user, secret, scoper) if err != nil { t.Logf("could not initialize spectre: %v", err) t.Fail() @@ -42,27 +46,12 @@ WithCounter(counter), WithScope(Scope(scope)), ) -import ( "strconv" +func TestSpectre(t *testing.T) { t.Log("passwords did not match") t.Fail() } }) - } -} - -// From the website sanity check -func TestSanity(t *testing.T) { - s, err := New("Robert Lee Mitchell", "banana colored duckling") - if err != nil { - t.Logf("failed sanity check: %v", err) - t.FailNow() - } - - pw := s.Site("masterpasswordapp.com") - if pw != "Jejr5[RepuSosp" { - t.Log("failed sanity check") - t.FailNow() } }