Ejemplo n.º 1
0
            public IData ProcessFile()
            {
                if (fileContent == null)
                {
                    throw new InvalidOperationException("Invalid input data: null");
                }

                var decoder = new PemDecoder();
                var result  = decoder.ReadData(fileContent);

                if (result == null)
                {
                    foreach (var error in decoder.Errors)
                    {
                        plugin.Log.Error(error);
                    }
                    return(null);
                }

                foreach (var warning in result.Warnings)
                {
                    plugin.Log.Warning(warning);
                }

                return(new PemData(result));
            }
Ejemplo n.º 2
0
        public void EmptyPemShouldReturnEmptyByteArray()
        {
            var pem = "";

            var result = PemDecoder.DecodeSection(pem, "Bar");

            result.Length.Should().Be(0);
        }
Ejemplo n.º 3
0
        public void PemWithoutMatchingSectionShouldReturnEmptyByteArray()
        {
            var pem = @"-----BEGIN Foo-----
data...
-----END Foo-----";

            var result = PemDecoder.DecodeSection(pem, "Bar");

            result.Length.Should().Be(0);
        }
Ejemplo n.º 4
0
        public void PemWithSingleSectionThatMatchesShouldReturnDecodedData()
        {
            var pem = @"-----BEGIN Foo-----
QmFy
-----END Foo-----";

            var result = PemDecoder.DecodeSection(pem, "Foo");

            result.Length.Should().Be(3);
            Encoding.UTF8.GetString(result).Should().Be("Bar");
        }
Ejemplo n.º 5
0
            public bool CanHandleFile(string filename)
            {
                if (!File.Exists(filename))
                {
                    throw new FileNotFoundException(string.Format(
                                                        "File {0} could not be found;", filename));
                }

                FileName    = filename;
                fileContent = File.ReadAllBytes(filename);

                return(PemDecoder.IsPemData(fileContent));
            }