Skip to content
Snippets Groups Projects
Commit 5828879b authored by Jono Wenger's avatar Jono Wenger
Browse files

Merge branch 'sessionConverter' into 'release'

Add function to convert session to version 2.

See merge request !305
parents 029db5c3 a8b441bf
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@ package user
const (
NotStarted uint32 = iota // Set on session creation
KeyGenComplete = 1 //Set upon generation of session information
PermissioningComplete = 2 //Set upon completion of RegisterWithPermissioning
UDBComplete = 3 //Set upon completion of RegisterWithUdb
KeyGenComplete = 1000 // Set upon generation of session information
PermissioningComplete = 2000 // Set upon completion of RegisterWithPermissioning
UDBComplete = 3000 // Set upon completion of RegisterWithUdb
)
......@@ -159,9 +159,28 @@ func LoadSession(store globals.Storage, password string) (Session, error) {
// Set storage pointer
session.store = store
session.password = password
// Update the session object to version 2 if it is currently version 1
if wrappedSession.Version == 1 {
ConvertSessionV1toV2(&session)
}
return &session, nil
}
// ConvertSessionV1toV2 converts the session object from version 1 to version 2.
// This conversion includes:
// 1. Changing the RegState values to the new integer values (1 to 2000, and 2
// to 3000).
func ConvertSessionV1toV2(s *SessionObj) {
// Convert RegState to new values
if *s.RegState == 1 {
*s.RegState = 2000
} else if *s.RegState == 2 {
*s.RegState = 3000
}
}
//processSession: gets the loadLocation and decrypted wrappedSession
func processSession(store globals.Storage, password string) (*SessionStorageWrapper, uint8, error) {
var wrappedSession *SessionStorageWrapper
......@@ -458,7 +477,7 @@ func (s *SessionObj) GetRegState() uint32 {
}
func (s *SessionObj) SetRegState(rs uint32) error {
prevRs := rs - 1
prevRs := rs - 1000
b := atomic.CompareAndSwapUint32(s.RegState, prevRs, rs)
if !b {
return errors.New("Could not increment registration state")
......
package user
const SessionVersion = 1
const SessionVersion = 2
......@@ -586,6 +586,45 @@ func TestSessionObj_PopGarbledMessages(t *testing.T) {
}
// Tests ConvertSessionV1toV2() by creating an empty session object and setting
// the RegState to the version 1, running it through the function, and testing
// that RegState has values that match version 2.
func TestSessionObj_ConvertSessionV1toV2(t *testing.T) {
ses := SessionObj{}
number := uint32(0)
ses.RegState = &number
ConvertSessionV1toV2(&ses)
if *ses.RegState != 0 {
t.Errorf("ConvertSessionV1toV2() did not properly convert the "+
"session object's RegState\n\texpected: %v\n\treceived: %v",
0, *ses.RegState)
}
number = uint32(1)
ses.RegState = &number
ConvertSessionV1toV2(&ses)
if *ses.RegState != 2000 {
t.Errorf("ConvertSessionV1toV2() did not properly convert the "+
"session object's RegState\n\texpected: %v\n\treceived: %v",
2000, *ses.RegState)
}
number = uint32(2)
ses.RegState = &number
ConvertSessionV1toV2(&ses)
if *ses.RegState != 3000 {
t.Errorf("ConvertSessionV1toV2() did not properly convert the "+
"session object's RegState\n\texpected: %v\n\treceived: %v",
3000, *ses.RegState)
}
}
func GenerateTestMessages(size int) []*format.Message {
msgs := make([]*format.Message, size)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment