Skip to content

Commit

Permalink
review: remove 'as committed' option all together
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Bryce committed Jan 24, 2024
1 parent 3e90913 commit e40de45
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 91 deletions.
7 changes: 0 additions & 7 deletions simplehash/hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ func (h *Hasher) applyEventOptions(o HashOptions, event *v2assets.EventResponse)
PublicFromPermissionedEvent(event)
}

// If the caller is responsible for evidence confirmation they will have a
// pending event in their hand. But ultimately it is the confirmed record
// that is evidential and subject to public verification.
if o.asCommitted {
event.ConfirmationStatus = v2assets.ConfirmationStatus_COMMITTED
}

// force the commited time in the hash. only useful to the service that is
// actually doing the committing. public consumers only ever see confirmed
// events with the timestamp already in place.
Expand Down
7 changes: 0 additions & 7 deletions simplehash/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
type HashOptions struct {
accumulateHash bool
publicFromPermissioned bool
asCommitted bool
prefix []byte
committed *timestamppb.Timestamp
idcommitted []byte
Expand Down Expand Up @@ -61,9 +60,3 @@ func WithPublicFromPermissioned() HashOption {
o.publicFromPermissioned = true
}
}

func WithAsCommitted() HashOption {
return func(o *HashOptions) {
o.asCommitted = true
}
}
61 changes: 3 additions & 58 deletions simplehash/schemav2.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,7 @@ func (h *HasherV2) HashEvent(event *v2assets.EventResponse, opts ...HashOption)
opt(&o)
}

var err error

if o.publicFromPermissioned {
PublicFromPermissionedEvent(event)
}

// If the caller is responsible for evidence confirmation they will have a
// pending event in their hand. But ultimately it is the confirmed record
// that is evidential and subject to public verification.
if o.asCommitted {
event.ConfirmationStatus = v2assets.ConfirmationStatus_COMMITTED
}

// force the commited time in the hash. only useful to the service that is
// actually doing the committing. public consumers only ever see confirmed
// events with the timestamp already in place.
if o.committed != nil {
event.TimestampCommitted = o.committed
}
h.Hasher.applyEventOptions(o, event)

// Note that we _don't_ take any notice of confirmation status.

Expand All @@ -97,23 +79,7 @@ func (h *HasherV2) HashEvent(event *v2assets.EventResponse, opts ...HashOption)
}

// Hash data accumulation starts here

// By default, one hash at at time with a reset.
if !o.accumulateHash {
h.hasher.Reset()
}

// If the prefix is provided it must be first.
if len(o.prefix) != 0 {
h.hasher.Write(o.prefix)
}

// If the idcommitted is provided, add it to the hash immediately before the
// event data.

if o.idcommitted != nil {
h.hasher.Write(o.idcommitted)
}
h.Hasher.applyHashingOptions(o)

return V2HashEvent(h.hasher, v2Event)
}
Expand All @@ -133,14 +99,6 @@ func (h *HasherV2) HashEventJSON(event []byte, opts ...HashOption) error {
for _, opt := range opts {
opt(&o)
}

var err error

// By default, one hash at at time with a reset.
if !o.accumulateHash {
h.Reset()
}

if o.publicFromPermissioned {
// It is api response data, so the details of protected vs public should already have been dealt with.
return ErrInvalidOption
Expand All @@ -151,20 +109,7 @@ func (h *HasherV2) HashEventJSON(event []byte, opts ...HashOption) error {
return err
}

// If the caller is responsible for evidence confirmation they will have a
// pending event in their hand. But ultimately it is the confirmed record
// that is evidential and subject to public verification.
if o.asCommitted {
// TODO: This probably is also not legit for an api consumer, but it
// does let the customer *anticipate* the hash and check we produce the
// correct one.
v2Event.ConfirmationStatus = v2assets.ConfirmationStatus_name[int32(v2assets.ConfirmationStatus_CONFIRMED)]
}

// If the idcommitted is provided, add it to the hash first
if o.idcommitted != nil {
h.hasher.Write(o.idcommitted)
}
h.Hasher.applyHashingOptions(o)

return V2HashEvent(h.hasher, v2Event)
}
Expand Down
4 changes: 0 additions & 4 deletions simplehash/schemav3.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ func (h *HasherV3) HashEvent(event *v2assets.EventResponse, opts ...HashOption)
opt(&o)
}

if o.asCommitted {
return fmt.Errorf("the v3 schema does not include confirmation_status: %w", ErrInvalidOption)
}

h.applyEventOptions(o, event)

v3Event, err := V3FromEventResponse(h.marshaler, event)
Expand Down
15 changes: 0 additions & 15 deletions simplehash/schemav3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,6 @@ func TestHasherV3_HashEvent(t *testing.T) {
false,
expectedHashAllV3,
},
{
"confirmation_status not supported",
fields{
Hasher: Hasher{
sha256.New(),
NewEventMarshaler(),
},
},
args{
validEventsV2,
[]HashOption{WithAsCommitted()},
},
true,
"",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit e40de45

Please sign in to comment.