Esempio n. 1
0
        public SnapshotStore(
            IRepository <Uri> uriRepository,
            IRepository <int> intRepository,
            FastCdc fastCdc,
            string hashAlgorithmName,
            IPrompt prompt,
            IProbe probe,
            int parallelizeChunkThreshold)
        {
            _uriRepository             = uriRepository;
            _intRepository             = intRepository;
            _fastCdc                   = fastCdc;
            _hashAlgorithmName         = hashAlgorithmName;
            _probe                     = probe;
            _parallelizeChunkThreshold = parallelizeChunkThreshold;

            if (parallelizeChunkThreshold <= 0)
            {
                throw new ArgumentException(
                          "Value must be larger than zero",
                          nameof(parallelizeChunkThreshold));
            }

            _currentSnapshotId = FetchCurrentSnapshotId();

            if (_currentSnapshotId == null)
            {
                _salt       = AesGcmCrypto.GenerateSalt();
                _iterations = AesGcmCrypto.Iterations;
            }
            else
            {
                var snapshotReference = GetSnapshotReference(
                    _currentSnapshotId.Value);

                _salt       = snapshotReference.Salt;
                _iterations = snapshotReference.Iterations;
            }

            _key = new Lazy <byte[]>(() =>
            {
                var password = _currentSnapshotId == null
                    ? prompt.NewPassword()
                    : prompt.ExistingPassword();

                return(AesGcmCrypto.PasswordToKey(password, _salt, _iterations));
            });
        }
 public string NewPassword()
 {
     return(GetEnvironmentPassword()
            ?? GetProcessPassword()
            ?? _prompt.NewPassword());
 }