Exemplo n.º 1
0
        /// <summary>
        /// Returns the stored value for testing purposes only. This function will attempt to await the
        /// last task (if any) writing to the the metric's storage engine before returning a value.
        /// @throws [NullPointerException] if no value is stored
        /// </summary>
        /// <param name="pingName">represents the name of the ping to retrieve the metric for.
        /// Defaults to the first value in `sendInPings`</param>
        /// <returns>value of the stored metric</returns>
        /// <exception cref="System.NullReferenceException">Thrown when the metric contains no value</exception>
        public JweData TestGetValue(string pingName = null)
        {
            Dispatchers.AssertInTestingMode();

            if (!TestHasValue(pingName))
            {
                throw new NullReferenceException();
            }

            string ping = pingName ?? sendInPings[0];

            JsonDocument jsonPayload = JsonDocument.Parse(
                LibGleanFFI.glean_jwe_test_get_value_as_json_string(this.handle, ping).AsString()
                );
            JsonElement root = jsonPayload.RootElement;

            return(new JweData(
                       root.GetProperty("header").GetString(),
                       root.GetProperty("key").GetString(),
                       root.GetProperty("init_vector").GetString(),
                       root.GetProperty("cipher_text").GetString(),
                       root.GetProperty("auth_tag").GetString()
                       ));
        }