private static async Task <PwsFileVersion> ReadVersionAsync(Stream stream) { if (await PwsFileV3.IsV3X(stream)) { return(PwsFileVersion.Version3); } return(PwsFileVersion.Unknown); }
/// <summary> /// Creates a new password safe with the given file version. /// </summary> /// <param name="stream">Stream to write the safe to.</param> /// <param name="passkey">Plain text password for the safe.</param> /// <param name="version">Version of the password safe to use. The result object type depends on that.</param> /// <returns>An empty password safe instance.</returns> /// <exception cref="NotSupportedException">Container version is not supported.</exception> public static async Task <PwsFile> CreateAsync(Stream stream, SecureString passkey, PwsFileVersion version) { PwsFile file; switch (version) { case PwsFileVersion.Version3: file = new PwsFileV3(stream, passkey, FileMode.Create); break; default: throw new NotSupportedException("Requested container version is not supported."); } await file.OpenAsync(); return(file); }