diff -r 000000000000 -r 6474c204b198 mobile/android/base/background/fxa/FxAccount20LoginDelegate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mobile/android/base/background/fxa/FxAccount20LoginDelegate.java Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,39 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.gecko.background.fxa; + +import java.io.UnsupportedEncodingException; +import java.security.GeneralSecurityException; + +import org.json.simple.JSONObject; +import org.mozilla.gecko.background.fxa.FxAccountClient10.CreateDelegate; +import org.mozilla.gecko.sync.Utils; + +/** + * An abstraction around providing an email and authorization token to the auth + * server. + */ +public class FxAccount20LoginDelegate implements CreateDelegate { + protected final byte[] emailUTF8; + protected final byte[] authPW; + + public FxAccount20LoginDelegate(byte[] emailUTF8, byte[] quickStretchedPW) throws UnsupportedEncodingException, GeneralSecurityException { + this.emailUTF8 = emailUTF8; + this.authPW = FxAccountUtils.generateAuthPW(quickStretchedPW); + } + + @SuppressWarnings("unchecked") + @Override + public JSONObject getCreateBody() throws FxAccountClientException { + final JSONObject body = new JSONObject(); + try { + body.put("email", new String(emailUTF8, "UTF-8")); + body.put("authPW", Utils.byte2Hex(authPW)); + return body; + } catch (UnsupportedEncodingException e) { + throw new FxAccountClientException(e); + } + } +}