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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/background/fxa/FxAccount20LoginDelegate.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,39 @@
     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 +
    1.13 +import org.json.simple.JSONObject;
    1.14 +import org.mozilla.gecko.background.fxa.FxAccountClient10.CreateDelegate;
    1.15 +import org.mozilla.gecko.sync.Utils;
    1.16 +
    1.17 +/**
    1.18 + * An abstraction around providing an email and authorization token to the auth
    1.19 + * server.
    1.20 + */
    1.21 +public class FxAccount20LoginDelegate implements CreateDelegate {
    1.22 +  protected final byte[] emailUTF8;
    1.23 +  protected final byte[] authPW;
    1.24 +
    1.25 +  public FxAccount20LoginDelegate(byte[] emailUTF8, byte[] quickStretchedPW) throws UnsupportedEncodingException, GeneralSecurityException {
    1.26 +    this.emailUTF8 = emailUTF8;
    1.27 +    this.authPW = FxAccountUtils.generateAuthPW(quickStretchedPW);
    1.28 +  }
    1.29 +
    1.30 +  @SuppressWarnings("unchecked")
    1.31 +  @Override
    1.32 +  public JSONObject getCreateBody() throws FxAccountClientException {
    1.33 +    final JSONObject body = new JSONObject();
    1.34 +    try {
    1.35 +      body.put("email", new String(emailUTF8, "UTF-8"));
    1.36 +      body.put("authPW", Utils.byte2Hex(authPW));
    1.37 +      return body;
    1.38 +    } catch (UnsupportedEncodingException e) {
    1.39 +      throw new FxAccountClientException(e);
    1.40 +    }
    1.41 +  }
    1.42 +}

mercurial