コード例 #1
0
        public void RoundTrip()
        {
            const string payload   = "Frank Denis rocks";
            string       signature = PasetoUtility.SignBytes(_publicKey, _privateKey, Encoding.UTF8.GetBytes(payload));

            Assert.Equal(payload, Encoding.UTF8.GetString(PasetoUtility.ParseBytes(_publicKey, signature).Payload));
        }
コード例 #2
0
        public void FooterCanBeParsed()
        {
            string footerText = "Hello friend";

            Assert.Equal(footerText, PasetoUtility.ParseFooter(PasetoUtility.SignBytes(_publicKey, _privateKey, new byte[0], footerText)));

            var footerJson = new Dictionary <string, object> {
                ["hello"] = "friend"
            };

            Assert.Equal(footerJson, PasetoUtility.ParseFooterJson(PasetoUtility.Sign(_publicKey, _privateKey, new PasetoInstance {
                Footer = footerJson
            })));
        }
コード例 #3
0
        public void TimezonesAreAllowed(string tokenJson)
        {
            var signedBytes = PasetoUtility.SignBytes(_publicKey, _privateKey, Encoding.UTF8.GetBytes(tokenJson));

            Assert.Equal("2018-03-20T07:00:00+00:00", PasetoUtility.Parse(_publicKey, signedBytes, validateTimes: false).Expiration.Value.ToString(Iso8601Format));
        }
コード例 #4
0
        public void InvalidJsonThrows(string str)
        {
            string token = PasetoUtility.SignBytes(_publicKey, _privateKey, Encoding.UTF8.GetBytes(str));

            Assert.Throws <PasetoFormatException>(() => PasetoUtility.Parse(_publicKey, token));
        }
コード例 #5
0
 public void EmptyTokenRoundTrip()
 {
     PasetoUtility.Parse(_publicKey, PasetoUtility.SignBytes(_publicKey, _privateKey, Encoding.UTF8.GetBytes("{}")));
     Assert.Equal("{}", Encoding.UTF8.GetString(PasetoUtility.ParseBytes(_publicKey, PasetoUtility.Sign(_publicKey, _privateKey, new PasetoInstance())).Payload));
 }