mattosaurus / PgpCore

.NET Core class library for using PGP
MIT License
245 stars 98 forks source link

VerifyClearAsync string,string overload does not update output variable #286

Open skimlik opened 7 months ago

skimlik commented 7 months ago

Method below

        public async Task<bool> VerifyClearAsync(string input, string output)
        {
            using (Stream inputStream = await input.GetStreamAsync())
            using (Stream outputStream = new MemoryStream())
            {
                bool verified = await VerifyClearAsync(inputStream, outputStream);

                outputStream.Seek(0, SeekOrigin.Begin);
                output = await outputStream.GetStringAsync();
                return verified;
            }
        }

should be declared as as

Task<bool> VerifyClearAsync(string input, ref string output)

ref keyword is mandatory, in order to get the output back. string is an immutable class

STR:

        string actual = string.Empty;
        var verified = await _pgp.VerifyCleanAsync(signed, actual);
        verified.Should().BeTrue(); // pass
        actual.Should().NotBeEmpty(); // fail
        actual.Should().BeEquivalentTo(expected); // fail: Expected actual to be equivalent to "this is a secret text" with a length of 21, but "" has a length of 0, differs near "" (index 0).
skimlik commented 7 months ago

I missed, this is async method, you can't use ref keyword in this case. But it isn't working as expected anyway

mattosaurus commented 5 months ago

I've updated the string based VerifyClearAsync method so that it no longer appears to return the message value. I'm not sure if this is the best solution but I don't really want to return a result object containing a bollean a dn string either. I'm open to suggestions if you've got a better way of doing this.