+
Skip to content

IDEN-298 add subject position to claim #425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 32 additions & 21 deletions claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,27 @@ type Claim struct {
value [4]ElemBytes
}

// Subject for the time being describes the location of ID (in index or value
// subjectFlag for the time being describes the location of ID (in index or value
// slots or nowhere at all).
//
// Values SubjectInvalid, SubjectObjectIndex, SubjectObjectValue
// presents for backward compatibility and for now means nothing.
type Subject byte
// Values subjectFlagInvalid presents for backward compatibility and for now means nothing.
type subjectFlag byte

const (
SubjectSelf Subject = iota // 000
SubjectInvalid // 001
SubjectOtherIdenIndex // 010
SubjectOtherIdenValue // 011
SubjectObjectIndex // 100
SubjectObjectValue // 101
subjectFlagSelf subjectFlag = iota // 000
_subjectFlagInvalid // nolint // 001
subjectFlagOtherIdenIndex // 010
subjectFlagOtherIdenValue // 011
)

type IDPosition uint8

const (
// IDPositionIndex means ID value is in index slots
IDPositionIndex IDPosition = iota + 1 // value 0 is position undefined
// IDPositionValue means ID value is in value slots
// IDPositionNone means ID value not located in claim.
IDPositionNone IDPosition = iota
// IDPositionIndex means ID value is in index slots.
IDPositionIndex
// IDPositionValue means ID value is in value slots.
IDPositionValue
)

Expand Down Expand Up @@ -324,17 +323,29 @@ func (c *Claim) GetSchemaHash() SchemaHash {
return schemaHash
}

func (c *Claim) setSubject(s Subject) {
// GetIDPosition returns the position at which the ID is stored.
func (c *Claim) GetIDPosition() IDPosition {
switch c.getSubject() {
case subjectFlagOtherIdenIndex:
return IDPositionIndex
case subjectFlagOtherIdenValue:
return IDPositionValue
default:
return IDPositionNone
}
}

func (c *Claim) setSubject(s subjectFlag) {
// clean first 3 bits
c.index[0][flagsByteIdx] &= 0b11111000
c.index[0][flagsByteIdx] |= byte(s)
}

func (c *Claim) getSubject() Subject {
func (c *Claim) getSubject() subjectFlag {
sbj := c.index[0][flagsByteIdx]
// clean all except first 3 bits
sbj &= 0b00000111
return Subject(sbj)
return subjectFlag(sbj)
}

func (c *Claim) setFlagExpiration(val bool) {
Expand Down Expand Up @@ -378,7 +389,7 @@ func (c *Claim) GetVersion() uint32 {
// SetIndexID sets id to index. Removes id from value if any.
func (c *Claim) SetIndexID(id ID) {
c.resetValueID()
c.setSubject(SubjectOtherIdenIndex)
c.setSubject(subjectFlagOtherIdenIndex)
copy(c.index[1][:], id[:])
}

Expand All @@ -396,7 +407,7 @@ func (c *Claim) getIndexID() ID {
// SetValueID sets id to value. Removes id from index if any.
func (c *Claim) SetValueID(id ID) {
c.resetIndexID()
c.setSubject(SubjectOtherIdenValue)
c.setSubject(subjectFlagOtherIdenValue)
copy(c.value[1][:], id[:])
}

Expand All @@ -415,17 +426,17 @@ func (c *Claim) getValueID() ID {
func (c *Claim) ResetID() {
c.resetIndexID()
c.resetValueID()
c.setSubject(SubjectSelf)
c.setSubject(subjectFlagSelf)
}

// GetID returns ID from claim's index of value.
// Returns error ErrNoID if ID is not set.
func (c *Claim) GetID() (ID, error) {
var id ID
switch c.getSubject() {
case SubjectOtherIdenIndex:
case subjectFlagOtherIdenIndex:
return c.getIndexID(), nil
case SubjectOtherIdenValue:
case subjectFlagOtherIdenValue:
return c.getValueID(), nil
default:
return id, ErrNoID
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载