Пример #1
0
 public bool TryReadBase64(byte[] buffer, int offset, int count, out int actual)
 {
     if (this.type == ValueHandleType.Base64)
     {
         actual = Math.Min(this.length, count);
         this.GetBase64(buffer, offset, actual);
         this.offset += actual;
         this.length -= actual;
         return(true);
     }
     if (((this.type == ValueHandleType.UTF8) && (count >= 3)) && ((this.length % 4) == 0))
     {
         try
         {
             int charCount = Math.Min((count / 3) * 4, this.length);
             actual       = Base64Encoding.GetBytes(this.bufferReader.Buffer, this.offset, charCount, buffer, offset);
             this.offset += charCount;
             this.length -= charCount;
             return(true);
         }
         catch (FormatException)
         {
         }
     }
     actual = 0;
     return(false);
 }
Пример #2
0
        public void Verify_Decode()
        {
            var e       = new Base64Encoding();
            var decoded = e.GetBytes(EncodedMessage);

            Assert.AreEqual(Message, decoded);
        }
Пример #3
0
 public byte[] ToByteArray()
 {
     byte[] buffer4;
     if (this.type == ValueHandleType.Base64)
     {
         byte[] buffer = new byte[this.length];
         this.GetBase64(buffer, 0, this.length);
         return(buffer);
     }
     if ((this.type == ValueHandleType.UTF8) && ((this.length % 4) == 0))
     {
         try
         {
             int num = (this.length / 4) * 3;
             if ((this.length > 0) && (this.bufferReader.Buffer[(this.offset + this.length) - 1] == 0x3d))
             {
                 num--;
                 if (this.bufferReader.Buffer[(this.offset + this.length) - 2] == 0x3d)
                 {
                     num--;
                 }
             }
             byte[] bytes = new byte[num];
             int    count = Base64Encoding.GetBytes(this.bufferReader.Buffer, this.offset, this.length, bytes, 0);
             if (count != bytes.Length)
             {
                 byte[] dst = new byte[count];
                 Buffer.BlockCopy(bytes, 0, dst, 0, count);
                 bytes = dst;
             }
             return(bytes);
         }
         catch (FormatException)
         {
         }
     }
     try
     {
         buffer4 = Base64Encoding.GetBytes(XmlConverter.StripWhitespace(this.GetString()));
     }
     catch (FormatException exception)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(exception.Message, exception.InnerException));
     }
     return(buffer4);
 }
Пример #4
0
        /// <summary>
        /// <see>http://nodejs.org/docs/v0.4.8/api/streams.html#stream.end</see>
        /// </summary>
        public override void end(string data, string encoding)
        {
            Encoding e = null;
            switch (encoding)
            {
                case "ascii":
                    e = Encoding.ASCII;
                    break;
                case "utf8":
                    e = Encoding.UTF8;
                    break;
                case "base64":
                    e = new Base64Encoding();
                    break;
            }
            if (e == null)
                throw new NotSupportedException(); // TODO: Should this raise OnError?

            // Send it across via a NodeBuffer.
            byte[] encoded = e.GetBytes(data);
            this.end(new NodeBuffer(this.Env, encoded, 0, encoded.Length));
        }
Пример #5
0
        public void Verify_Roundtrip()
        {
            var e = new Base64Encoding();

            Assert.AreEqual(EncodedMessage, e.GetString(e.GetBytes(EncodedMessage)));
        }