/** * Store a polymorphic pseudonym in the database. * @param user The User ID to store the polymorphic pseudonym for. * @param pp The polymorphic pseudonym to store. */ public void AddPolymorphic(string user, Pseudonym pp) { PolymorphicPseudonym pseudonym = new PolymorphicPseudonym(); pseudonym.user = user; pseudonym.pseudonym = pp.Encode(); pseudonym.id = System.Guid.NewGuid(); db.PolymorphicPseudonyms.InsertOnSubmit(pseudonym); db.SubmitChanges(); }
/** * Execute the <code>randomize</code> query * @return 2D array <code>result</code> with <code>result[0][0]</code> being the encoded randomized pseudonym. */ public string[][] Randomize() { string[] oneResult = new string[1]; Pseudonym pseudonym = Pseudonym.Decode(parameters[0]); pseudonym = pseudonym.Randomize(); oneResult[0] = pseudonym.Encode(); return(new string[][] { oneResult }); }
/** * Store a encrypted pseudonym in the database. * @param user The User ID to store the encrypted pseudonym for. * @param sp the SP ID to store the encrypted pseudonym for. * @param ep The encrypted pseudonym to store. */ public void AddEncrypted(string user, string sp, Pseudonym ep) { EncryptedPseudonym pseudonym = new EncryptedPseudonym(); pseudonym.user = user; pseudonym.sp = sp; pseudonym.pseudonym = ep.Encode(); pseudonym.id = System.Guid.NewGuid(); db.EncryptedPseudonyms.InsertOnSubmit(pseudonym); db.SubmitChanges(); }
/** * Execute the <code>getEP</code> query * @return 2D array <code>result</code> with <code>result[0][0]</code> being the encoded encrypted pseudonym. */ public string[][] GetEP() { Pseudonym ep = db.GetEncrypted(parameters[INDEX_UID], parameters[INDEX_SP]); if (ep == null) { Pseudonym pp = GetPolymorphicPseudonym(); ep = pseudonymProvider.GetEPAsync(pp, parameters[INDEX_SP]).Result; db.AddEncrypted(parameters[INDEX_UID], parameters[INDEX_SP], ep); } return(new string[][] { new string[] { ep.Encode() } }); }
/** * Get an encrypted pseudonym asynchronously. * @param pp The polymorphic pseudonym to get an encrypted pseudonym for. * @param sp The SP ID to get an encrypted pseudonym for. * @return A task that will result in the Encrypted Pseudonym. */ public async Task <Pseudonym> GetEPAsync(Pseudonym pp, string sp) { HttpClient client = new HttpClient(); HttpResponseMessage message = await client.GetAsync(string.Format(url, WebUtility.UrlEncode(pp.Encode()), WebUtility.UrlEncode(sp))); string epString = await message.Content.ReadAsStringAsync(); return(Pseudonym.Decode(epString)); }