mirror of
https://github.com/gomods/athens
synced 2026-02-03 11:00:32 +00:00
* Changed mongo.go to use new driver * Modified mongo cataloger * More new driver related changes * Change lister.go * Change saver.go * Change imports * Remove unnecessary Count query * Use IndexView for indexing * Rename ModuleStore fields * Use map of key:sorting-order for creating the index * Minor changes * Use client options to configure mongo client * Use method chaining * gofmt changes * Change imports * Fix some build errors * Use new GridFS API * Fix more build errors * Add Go Mongo driver to dependency modules * Use multierror * Leave download stream open * Remove mgo error handling * Copy zip instead of loading all in memory * Use context.WithTimeout() wherever possible * Raise KindNotFound when mod@ver isn't found * NopCloser not needed * Fix IndexView error * Fix build errors * Remove another mgo error usage * Fix build error * Changes according to review * Formatting changes as per gofmt * Modify gofmt argument to show the expected formatting (diff) * Handle ErrNoDocument error and error arising from query execution * Fix kind of returned error * Minor changes * Bug fixes * gofmt related changes * Minor change * Use Insecure from MongoConfig, remove Insecure from global Config * Remove stray print statement
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
// Copyright 2018 by David A. Golden. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
// not use this file except in compliance with the License. You may obtain
|
|
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
package scram
|
|
|
|
import "sync"
|
|
|
|
// Server implements the server side of SCRAM authentication. It holds
|
|
// configuration values needed to initialize new server-side conversations.
|
|
// Generally, this can be persistent within an application.
|
|
type Server struct {
|
|
sync.RWMutex
|
|
credentialCB CredentialLookup
|
|
nonceGen NonceGeneratorFcn
|
|
hashGen HashGeneratorFcn
|
|
}
|
|
|
|
func newServer(cl CredentialLookup, fcn HashGeneratorFcn) (*Server, error) {
|
|
return &Server{
|
|
credentialCB: cl,
|
|
nonceGen: defaultNonceGenerator,
|
|
hashGen: fcn,
|
|
}, nil
|
|
}
|
|
|
|
// WithNonceGenerator replaces the default nonce generator (base64 encoding of
|
|
// 24 bytes from crypto/rand) with a custom generator. This is provided for
|
|
// testing or for users with custom nonce requirements.
|
|
func (s *Server) WithNonceGenerator(ng NonceGeneratorFcn) *Server {
|
|
s.Lock()
|
|
defer s.Unlock()
|
|
s.nonceGen = ng
|
|
return s
|
|
}
|
|
|
|
// NewConversation constructs a server-side authentication conversation.
|
|
// Conversations cannot be reused, so this must be called for each new
|
|
// authentication attempt.
|
|
func (s *Server) NewConversation() *ServerConversation {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
return &ServerConversation{
|
|
nonceGen: s.nonceGen,
|
|
hashGen: s.hashGen,
|
|
credentialCB: s.credentialCB,
|
|
}
|
|
}
|