세션키를 자체 발급하도록 수정
This commit is contained in:
@ -1,6 +1,11 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"repositories.action2quare.com/ayo/gocommon"
|
||||
)
|
||||
@ -18,3 +23,58 @@ type Authorization struct {
|
||||
Uid string `bson:"u" json:"u"`
|
||||
Email string `bson:"em" json:"em"`
|
||||
}
|
||||
|
||||
type Provider interface {
|
||||
New(*Authorization) (string, error)
|
||||
Delete(primitive.ObjectID) error
|
||||
Query(string) (*Authorization, error)
|
||||
}
|
||||
|
||||
type Consumer interface {
|
||||
Query(string) (*Authorization, error)
|
||||
Touch(string) (*Authorization, error)
|
||||
}
|
||||
|
||||
type storagekey string
|
||||
type publickey string
|
||||
|
||||
var r = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
func make_storagekey(acc primitive.ObjectID) storagekey {
|
||||
bs := [4]byte{}
|
||||
binary.LittleEndian.PutUint32(bs[:], r.Uint32())
|
||||
|
||||
return storagekey(acc.Hex() + hex.EncodeToString(bs[2:]))
|
||||
}
|
||||
|
||||
func storagekey_to_publickey(sk storagekey) publickey {
|
||||
bs, _ := hex.DecodeString(string(sk))
|
||||
|
||||
acc := bs[:12]
|
||||
cs := bs[12:]
|
||||
|
||||
encoded := [14]byte{}
|
||||
for i, v := range acc[:] {
|
||||
encoded[i] = (v ^ cs[0]) ^ cs[1]
|
||||
}
|
||||
encoded[12] = cs[0]
|
||||
encoded[13] = cs[1]
|
||||
|
||||
return publickey(hex.EncodeToString(encoded[:]))
|
||||
}
|
||||
|
||||
func publickey_to_storagekey(pk publickey) storagekey {
|
||||
bs, _ := hex.DecodeString(string(pk))
|
||||
|
||||
acc := bs[:12]
|
||||
cs := bs[12:]
|
||||
|
||||
decoded := [14]byte{}
|
||||
for i, v := range acc[:] {
|
||||
decoded[i] = (v ^ cs[1]) ^ cs[0]
|
||||
}
|
||||
decoded[12] = cs[0]
|
||||
decoded[13] = cs[1]
|
||||
|
||||
return storagekey(hex.EncodeToString(decoded[:]))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user