< Summary

Information
Class: Renci.SshNet.Security.Org.BouncyCastle.Utilities.Encoders.Hex
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\BouncyCastle\util\encoders\Hex.cs
Line coverage
15%
Covered lines: 6
Uncovered lines: 32
Coverable lines: 38
Total lines: 129
Line coverage: 15.7%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.cctor()100%1100%
.ctor()100%10%
ToHexString(...)100%10%
ToHexString(...)100%10%
Encode(...)100%10%
Encode(...)100%10%
Encode(...)100%10%
Encode(...)100%10%
Decode(...)100%10%
Decode(...)100%1100%
Decode(...)100%10%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\BouncyCastle\util\encoders\Hex.cs

#LineLine coverage
 1using System.IO;
 2using System.Text;
 3
 4namespace Renci.SshNet.Security.Org.BouncyCastle.Utilities.Encoders
 5{
 6    /// <summary>
 7    /// Class to decode and encode Hex.
 8    /// </summary>
 9    internal sealed class Hex
 10    {
 111        private static readonly HexEncoder encoder = new HexEncoder();
 12
 013        private Hex()
 014        {
 015        }
 16
 17        public static string ToHexString(
 18            byte[] data)
 019        {
 020            return ToHexString(data, 0, data.Length);
 021        }
 22
 23        public static string ToHexString(
 24            byte[]  data,
 25            int    off,
 26            int    length)
 027        {
 028            byte[] hex = Encode(data, off, length);
 029            return Encoding.UTF8.GetString(hex, 0, hex.Length);
 030        }
 31
 32        /**
 33         * encode the input data producing a Hex encoded byte array.
 34         *
 35         * @return a byte array containing the Hex encoded data.
 36         */
 37        public static byte[] Encode(
 38            byte[] data)
 039        {
 040            return Encode(data, 0, data.Length);
 041        }
 42
 43        /**
 44         * encode the input data producing a Hex encoded byte array.
 45         *
 46         * @return a byte array containing the Hex encoded data.
 47         */
 48        public static byte[] Encode(
 49            byte[]  data,
 50            int    off,
 51            int    length)
 052        {
 053            MemoryStream bOut = new MemoryStream(length * 2);
 54
 055            encoder.Encode(data, off, length, bOut);
 56
 057            return bOut.ToArray();
 058        }
 59
 60        /**
 61         * Hex encode the byte data writing it to the given output stream.
 62         *
 63         * @return the number of bytes produced.
 64         */
 65        public static int Encode(
 66            byte[]  data,
 67            Stream  outStream)
 068        {
 069            return encoder.Encode(data, 0, data.Length, outStream);
 070        }
 71
 72        /**
 73         * Hex encode the byte data writing it to the given output stream.
 74         *
 75         * @return the number of bytes produced.
 76         */
 77        public static int Encode(
 78            byte[]  data,
 79            int    off,
 80            int    length,
 81            Stream  outStream)
 082        {
 083            return encoder.Encode(data, off, length, outStream);
 084        }
 85
 86        /**
 87         * decode the Hex encoded input data. It is assumed the input data is valid.
 88         *
 89         * @return a byte array representing the decoded data.
 90         */
 91        public static byte[] Decode(
 92            byte[] data)
 093        {
 094            MemoryStream bOut = new MemoryStream((data.Length + 1) / 2);
 95
 096            encoder.Decode(data, 0, data.Length, bOut);
 97
 098            return bOut.ToArray();
 099        }
 100
 101        /**
 102         * decode the Hex encoded string data - whitespace will be ignored.
 103         *
 104         * @return a byte array representing the decoded data.
 105         */
 106        public static byte[] Decode(
 107            string data)
 18108        {
 18109            MemoryStream bOut = new MemoryStream((data.Length + 1) / 2);
 110
 18111            encoder.DecodeString(data, bOut);
 112
 18113            return bOut.ToArray();
 18114        }
 115
 116        /**
 117         * decode the Hex encoded string data writing it to the given output stream,
 118         * whitespace characters will be ignored.
 119         *
 120         * @return the number of bytes produced.
 121         */
 122        public static int Decode(
 123            string  data,
 124            Stream  outStream)
 0125        {
 0126            return encoder.DecodeString(data, outStream);
 0127        }
 128    }
 129}