public static unsafe bool TryCapturePassword(string instructions, IPersistedKeyCapture @in, TextWriter @out, TextWriter error, out byte *password, out int passwordLength) { if (@in.TryReadPersisted(out password, out passwordLength)) { return(true); } var result = TryCapturePassword(instructions, @in as IKeyCapture, @out, error, out password, out passwordLength); if (result) { @in.Sink(password, passwordLength); } return(result); }
public static unsafe byte *LoadSecretKeyPointerFromFileStream(string keyFilePath, FileStream keyFileStream, IPersistedKeyCapture capture, [CallerMemberName] string callerMemberName = null) { if (keyFileStream.CanSeek) { keyFileStream.Seek(0, SeekOrigin.Begin); } if (!KeyFileManager.TryLoadKeyFile(keyFileStream, Console.Out, Console.Error, out var sk, capture)) { throw new InvalidOperationException( $"{callerMemberName}: Cannot load key file at path '{keyFilePath}'"); } return(sk); }
public static unsafe bool TryLoadKeyFile(FileStream keyFileStream, TextWriter @out, TextWriter error, out byte *secretKey, IPersistedKeyCapture capture) { if (capture == default) { throw new InvalidOperationException(Strings.InvalidKeyCapture); } secretKey = default; return(TryCapturePassword(Strings.LoadKeyInstructions, capture, @out, error, out var password, out var passwordLength) && TryLoadKeyFile(keyFileStream, @out, error, ref secretKey, password, passwordLength, true)); }