1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00

Update validation

This commit is contained in:
mcrakhman 2023-08-21 10:48:21 +02:00
parent 6caa9214b7
commit 4592760ece
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
2 changed files with 8 additions and 9 deletions

View file

@ -33,31 +33,31 @@ func PrepareDeleteConfirmation(privKey crypto.PrivKey, spaceId, peerId, networkI
return
}
func ValidateDeleteConfirmation(pubKey crypto.PubKey, networkId string, deleteConfirm *DeletionConfirmPayloadWithSignature) (spaceId string, err error) {
func ValidateDeleteConfirmation(pubKey crypto.PubKey, spaceId, networkId string, deleteConfirm *DeletionConfirmPayloadWithSignature) (err error) {
res, err := pubKey.Verify(deleteConfirm.GetDeletionPayload(), deleteConfirm.GetSignature())
if err != nil {
return
}
if !res {
err = errSignatureIncorrect
return
return errSignatureIncorrect
}
payload := &DeletionConfirmPayload{}
err = payload.Unmarshal(deleteConfirm.GetDeletionPayload())
if err != nil {
return
}
spaceId = payload.SpaceId
if payload.SpaceId != spaceId {
return errSpaceIdIncorrect
}
if payload.NetworkId != networkId {
err = errNetworkIsIncorrect
return
return errNetworkIsIncorrect
}
accountRaw, err := crypto.UnmarshalEd25519PublicKeyProto(payload.AccountIdentity)
if err != nil {
return
}
if !bytes.Equal(pubKey.Storage(), accountRaw.Storage()) {
err = errAccountIncorrect
return errAccountIncorrect
}
return
}

View file

@ -9,7 +9,6 @@ func TestValidateDeleteConfirmation(t *testing.T) {
fx := newFixture(t)
delConfirm, err := PrepareDeleteConfirmation(fx.accountPrivKey, fx.spaceId, fx.peerId, fx.networkKey.GetPublic().Network())
require.NoError(t, err)
spaceId, err := ValidateDeleteConfirmation(fx.accountKey, fx.networkKey.GetPublic().Network(), delConfirm)
err = ValidateDeleteConfirmation(fx.accountKey, fx.spaceId, fx.networkKey.GetPublic().Network(), delConfirm)
require.NoError(t, err)
require.Equal(t, fx.spaceId, spaceId)
}