Example #1
0
        /// <summary>
        /// Checks the verified purchase result.
        /// </summary>
        /// <returns><c>true</c>, if purchase result matches the provided nonce, <c>false</c> otherwise.</returns>
        /// <param name="result">Result of the IRequest returned from VerifyPurchase</param>
        /// <param name="nonce">Nonce string from the original request.</param>
        public bool CheckVerifiedPurchaseResult(IDictionary <string, object> result, string nonce)
        {
            if (!result.ContainsKey("ver"))
            {
                return(false);
            }
            string ver = result["ver"] as String;

            byte[] key      = Encoding.UTF8.GetBytes(ApplicationKey);
            string expected = WebData.HexDigest(key, nonce + "OK");

            return(expected == ver);
        }
Example #2
0
        /// <summary>
        /// A WWW with an x-tsumanga-sign header signing the POST data
        /// using the specified key.
        /// </summary>
        /// <returns>
        /// The WWW object
        /// </returns>
        /// <param name='url'>
        /// URL (to be appended to the host from the constructor)
        /// </param>
        /// <param name='key'>
        /// A byte array that will be the HMAC key used to sign the data.
        /// </param>
        /// <param name='body'>
        /// An object that will be serialised to JSON and encoded as UTF8,
        /// which will then be used with the key to make an HMAC signature.
        /// </param>
        internal WWW SignedWWW(string url, byte[] key, object body, string methodOverride)
        {
            string json = (body is string) ? body as string : WebData.JsonSerialise(body);
            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers["Content-Type"] = "application/json";
            byte[] data = Encoding.UTF8.GetBytes(json);
            // now use gzip content encoding if it makes the request smaller
            byte[] zippedData = WebData.Gzip(data);
            if (zippedData.Length < data.Length)
            {
                data = zippedData;
                headers["Content-Encoding"] = "gzip";
            }
            headers["x-tsumanga-sign"] = WebData.HexDigest(key, data);
            if (methodOverride != null)
            {
                headers["X-HTTP-Method-Override"] = methodOverride;
            }

            return(new WWW(WebServiceHost + url, data, headers));
        }