public void Write(KeyMetadata metadata)
        {
            CreateDir();
            var meta_file = Path.Combine(_location, "meta");
            var file = meta_file + ".temp";
            if (!_overwrite && File.Exists(meta_file))
            {
                success = false;
                return;
            }
            try
            {
                _filePaths.Add(file);
                using (var stream = new FileStream(file, FileMode.Create))
                using (var writer = new StreamWriter(stream))
                {
                    if (metadata.OriginallyOfficial && metadata.ValidOfficial())
                    {
                        writer.Write(new OfficialKeyMetadata(metadata).ToJson());
                    }
                    else
                    {
                        writer.Write(metadata.ToJson());
                    }

                    
                }
            }
            catch (Exception ex)
            {
                _exceptions.Add(ex);
                success = false;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyMetadata"/> class.
        /// </summary>
        /// <param name="metadata">The metadata.</param>
        public OfficialKeyMetadata(KeyMetadata metadata)
        {
            Name    = metadata.Name ?? String.Empty;
            Purpose = metadata.Purpose;
#pragma warning disable 618
            KeyType = metadata.KeyType;
#pragma warning restore 618

            if (!metadata.ValidOfficial())
            {
                throw new InvalidDataException("Official KeySet must only have one keytype");
            }

            KeyType = metadata.OfficialKeyType();


            Encrypted = metadata.Encrypted;
            Versions  = metadata.Versions.Select(it => new OfficialKeyVersion(it)).ToList();
        }