package com.nextcloud.android.sso.aidl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  Nextcloud SingleSignOn
 *
 *  @author David Luhmer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class NextcloudRequest implements Serializable {

    static final long serialVersionUID = 215521212534236L; //assign a long value

    public String method;
    public Map<String, List<String>> header = new HashMap<>();
    public Map<String, String> parameter = new HashMap<>();
    public String requestBody;
    public String url;
    public String token;
    public String accountName;

    private NextcloudRequest() { }

    public static class Builder {
        private NextcloudRequest ncr;

        public Builder() {
            ncr = new NextcloudRequest();
        }

        public NextcloudRequest build() {
            return ncr;
        }

        public Builder setMethod(String method) {
            ncr.method = method;
            return this;
        }

        public Builder setHeader(Map<String, List<String>> header) {
            ncr.header = header;
            return this;
        }

        public Builder setParameter(HashMap<String, String> parameter) {
            ncr.parameter = parameter;
            return this;
        }

        public Builder setRequestBody(String requestBody) {
            ncr.requestBody = requestBody;
            return this;
        }

        public Builder setUrl(String url) {
            ncr.url = url;
            return this;
        }

        public Builder setToken(String token) {
            ncr.token = token;
            return this;
        }

        public Builder setAccountName(String accountName) {
            ncr.accountName = accountName;
            return this;
        }
    }
}
@@ -1,148 +1,5 @@
-package com.nextcloud.android.sso.aidl;%0A%0Aimport java.io.Serializable;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0A/*
+/
 *%0A *
@@ -705,16 +705,158 @@
 %3E.%0A */%0A%0A
+package com.nextcloud.android.sso.aidl;%0A%0Aimport java.io.Serializable;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0A
 public c
@@ -908,16 +908,24 @@
  %7B%0A%0A    
+private 
 static f
@@ -971,9 +971,9 @@
 3423
-6
+7
 L; /
@@ -1218,24 +1218,55 @@
 ring token;%0A
+    public String packageName;%0A
     public S
@@ -1844,20 +1844,16 @@
 rameter(
-Hash
 Map%3CStri
@@ -2305,32 +2305,171 @@
 his;%0A        %7D%0A%0A
+        public Builder setPackageName(String packageName) %7B%0A            ncr.packageName = packageName;%0A            return this;%0A        %7D%0A%0A
         public B
@@ -2596,9 +2596,672 @@
 %7D%0A    %7D%0A
-%7D
+%0A    public boolean validateToken(String token) %7B%0A        // As discussed with Lukas R. at the Nextcloud Conf 2018, always compare whole strings%0A        // and don't exit prematurely if the string does not match anymore to prevent timing-attacks%0A        return isEqual(this.token.getBytes(), token.getBytes());%0A    %7D%0A%0A    // Taken from http://codahale.com/a-lesson-in-timing-attacks/%0A    private static boolean isEqual(byte%5B%5D a, byte%5B%5D b) %7B%0A        if (a.length != b.length) %7B%0A            return false;%0A        %7D%0A%0A        int result = 0;%0A        for (int i = 0; i %3C a.length; i++) %7B%0A            result %7C= a%5Bi%5D %5E b%5Bi%5D;%0A        %7D%0A        return result == 0;%0A    %7D%0A%7D%0A

Update NextcloudRequest to match latest version of nextcloud-android