mobile/android/base/background/fxa/QuickPasswordStretcher.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/background/fxa/QuickPasswordStretcher.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,34 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +package org.mozilla.gecko.background.fxa;
     1.9 +
    1.10 +import java.io.UnsupportedEncodingException;
    1.11 +import java.security.GeneralSecurityException;
    1.12 +import java.util.HashMap;
    1.13 +import java.util.Map;
    1.14 +
    1.15 +import org.mozilla.gecko.sync.Utils;
    1.16 +
    1.17 +public class QuickPasswordStretcher implements PasswordStretcher {
    1.18 +  protected final String password;
    1.19 +  protected final Map<String, String> cache = new HashMap<String, String>();
    1.20 +
    1.21 +  public QuickPasswordStretcher(String password) {
    1.22 +    this.password = password;
    1.23 +  }
    1.24 +
    1.25 +  public synchronized byte[] getQuickStretchedPW(byte[] emailUTF8) throws UnsupportedEncodingException, GeneralSecurityException {
    1.26 +    if (emailUTF8 == null) {
    1.27 +      throw new IllegalArgumentException("emailUTF8 must not be null");
    1.28 +    }
    1.29 +    String key = Utils.byte2Hex(emailUTF8);
    1.30 +    if (!cache.containsKey(key)) {
    1.31 +      byte[] value = FxAccountUtils.generateQuickStretchedPW(emailUTF8, password.getBytes("UTF-8"));
    1.32 +      cache.put(key, Utils.byte2Hex(value));
    1.33 +      return value;
    1.34 +    }
    1.35 +    return Utils.hex2Byte(cache.get(key));
    1.36 +  }
    1.37 +}

mercurial