Beispiel #1
0
        public EnvCryptDat Load(DatFromFileLoaderOptions options)
        {
            if (!_myFile.Exists(options.DatFilePath))
            {
                return(new EnvCryptDat()
                {
                    Categories = new List <Category>()
                });
            }

            var xmlFromFile = _xmlReader.ReadAllText(options.DatFilePath);

            if (string.IsNullOrWhiteSpace(xmlFromFile))
            {
                throw new EnvCryptException("key file is empty: {0}", options.DatFilePath);
            }

            var xmlPoco = _xmlSerializationUtils.Deserialize(xmlFromFile);

            return(_xmlToPocoMapper.Map(xmlPoco));
        }
Beispiel #2
0
        public TKey Load(TLoadDetails keyFileDetails)
        {
            if (keyFileDetails == null || string.IsNullOrWhiteSpace(keyFileDetails.FilePath))
            {
                throw new EnvCryptException("key file path cannot be empty");
            }
            if (!_myFile.Exists(keyFileDetails.FilePath))
            {
                throw new EnvCryptException("key file does not exist: {0}", keyFileDetails);
            }

            var xmlFromFile = _xmlReader.ReadAllText(keyFileDetails.FilePath);

            if (string.IsNullOrWhiteSpace(xmlFromFile))
            {
                throw new EnvCryptException("key file is empty: {0}", keyFileDetails);
            }

            var xmlPoco = _xmlSerializationUtils.Deserialize(xmlFromFile);

            return(MapToKeyPoco(xmlPoco));
        }