示例#1
0
        public override bool IncrementToken()
        {
            bool result = false;

            if (input.IncrementToken())
            {
                char[] buffer = termAtt.TermBuffer();
                int    length = termAtt.TermLength();
                //look for the delimiter
                bool seen = false;
                for (int i = 0; i < length; i++)
                {
                    if (buffer[i] == delimiter)
                    {
                        termAtt.SetTermBuffer(buffer, 0, i);
                        payAtt.Payload = encoder.Encode(buffer, i + 1, (length - (i + 1)));
                        seen           = true;
                        break;//at this point, we know the whole piece, so we can exit.  If we don't see the delimiter, then the termAtt is the same
                    }
                }
                if (seen == false)
                {
                    //no delimiter
                    payAtt.Payload = null;
                }
                result = true;
            }
            return(result);
        }
示例#2
0
        public void Encoder_Throws_ArgumentNullException_On_Null_Payload()
        {
            IPayloadEncoder e = new PayloadEncoder();

            Assert.Throws <ArgumentNullException>(() =>
            {
                e.Encode(null);
                return(false);
            });
        }
示例#3
0
        public void Encoder_Returns_Expected()
        {
            // source : http://jwt.io sample

            var payload = new Dictionary <string, object>()
            {
                ["sub"]   = "1234567890",
                ["name"]  = "John Doe",
                ["admin"] = true
            };

            IPayloadEncoder e = new PayloadEncoder();

            var output = e.Encode(payload);

            Assert.Equal(output, "eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9");
        }