File tree Expand file tree Collapse file tree
AwsCryptographyPrimitives/runtimes/go/ImplementationFromDafny-go/ECDH Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -98,7 +98,13 @@ func (CompanionStruct_Default___) CalculateSharedSecret(curveSpec AwsCryptograph
9898 return Wrappers .Companion_Result_ .Create_Success_ (dafny .SeqOfBytes (sharedSecret ))
9999}
100100
101- func (CompanionStruct_Default___ ) CompressPublicKey (publicKeyInput dafny.Sequence , curveSpec AwsCryptographyPrimitivesTypes.ECDHCurveSpec ) Wrappers.Result {
101+ func (static CompanionStruct_Default___ ) CompressPublicKey (publicKeyInput dafny.Sequence , curveSpec AwsCryptographyPrimitivesTypes.ECDHCurveSpec ) Wrappers.Result {
102+ // We only need this because elliptic.MarshalCompressed() doesn't return err handle and panics, so to avoid panic we pre-validate the key.
103+ validate := static .ValidatePublicKey (curveSpec , publicKeyInput )
104+
105+ if validate .IsFailure () {
106+ return validate
107+ }
102108 pkixPublicKey , err := x509 .ParsePKIXPublicKey (dafny .ToByteArray (publicKeyInput ))
103109 if err != nil {
104110 return Wrappers .Companion_Result_ .Create_Failure_ (AwsCryptographyPrimitivesTypes .Companion_Error_ .Create_AwsCryptographicPrimitivesError_ (dafny .SeqOfChars ([]dafny.Char (err .Error ())... )))
@@ -190,7 +196,7 @@ func (companion CompanionStruct_Default___) ValidatePublicKey(curveSpec AwsCrypt
190196 ecdhPublicKey , err := encodedPublicKey .(* ecdsa.PublicKey ).ECDH ()
191197
192198 if _ , err := curve .NewPublicKey (ecdhPublicKey .Bytes ()); err != nil {
193- return Wrappers .Companion_Result_ .Create_Failure_ (true )
199+ return Wrappers .Companion_Result_ .Create_Failure_ (AwsCryptographyPrimitivesTypes . Companion_Error_ . Create_AwsCryptographicPrimitivesError_ ( dafny . SeqOfChars ([]dafny. Char ( err . Error ()) ... )) )
194200 }
195201
196202 return Wrappers .Companion_Result_ .Create_Success_ (true )
You can’t perform that action at this time.
0 commit comments