/** * g_paste_clipboard_set_image: * @self: a #GPasteClipboard instance * * Put the image from the intern GtkClipboard in the #GPasteClipboard * * Returns: (transfer full): The new image if it was modified, or NULL */ G_PASTE_VISIBLE GdkPixbuf * g_paste_clipboard_set_image (GPasteClipboard *self) { g_return_val_if_fail (G_PASTE_IS_CLIPBOARD (self), NULL); GPasteClipboardPrivate *priv = self->priv; GdkPixbuf *image = gtk_clipboard_wait_for_image (priv->real); GdkPixbuf *ret = image; if (image) { gchar *checksum = g_compute_checksum_for_data (G_CHECKSUM_SHA256, (guchar *) gdk_pixbuf_get_pixels (image), -1); if (g_strcmp0 (checksum, self->priv->image_checksum) != 0) _g_paste_clipboard_select_image (self, image, checksum); else ret = NULL; g_free (checksum); } return ret; }
static gboolean parse_key_blob (guchar *bytes, gsize len, SeahorseSSHKeyData *data) { GString *fingerprint; gchar *digest; gsize n_digest; gsize i; digest = g_compute_checksum_for_data (G_CHECKSUM_MD5, bytes, len); if (!digest) return FALSE; n_digest = strlen (digest); fingerprint = g_string_sized_new ((n_digest * 3) / 2); for (i = 0; i < n_digest; i += 2) { if (i > 0) g_string_append_c (fingerprint, ':'); g_string_append_len (fingerprint, digest + i, 2); } g_free (digest); data->fingerprint = g_string_free (fingerprint, FALSE); return TRUE; }
static gchar * dacp_share_pairing_code (DACPShare * share, gchar * pair_txt, gchar passcode[4]) { int i; GString *pairing_code; gchar *pairing_string; gchar *ret; /* The pairing code is the MD5 sum of the concatenation of pair_txt * with the passcode, but the passcode takes 16-bits unicodes characters */ pairing_string = g_strnfill (PAIR_TXT_LENGTH + PASSCODE_LENGTH * 2, '\0'); g_strlcpy (pairing_string, pair_txt, PAIR_TXT_LENGTH + PASSCODE_LENGTH * 2); for (i = 0; i < 4; i++) { pairing_string[PAIR_TXT_LENGTH + i * 2] = passcode[i]; } pairing_code = g_string_new (g_compute_checksum_for_data (G_CHECKSUM_MD5, (guchar *) pairing_string, PAIR_TXT_LENGTH + PASSCODE_LENGTH * 2)); g_string_ascii_up (pairing_code); ret = pairing_code->str; g_string_free (pairing_code, FALSE); return ret; }
/** * pk_plugin_get_filename_md5: **/ static gchar * pk_plugin_get_filename_md5 (const gchar *filename) { gchar *md5 = NULL; gchar *data = NULL; gsize length; GError *error = NULL; gboolean ret; /* check is no longer exists */ ret = g_file_test (filename, G_FILE_TEST_EXISTS); if (!ret) goto out; /* get data */ ret = g_file_get_contents (filename, &data, &length, &error); if (!ret) { g_warning ("failed to open file %s: %s", filename, error->message); g_error_free (error); goto out; } /* check md5 is same */ md5 = g_compute_checksum_for_data (G_CHECKSUM_MD5, (const guchar *) data, length); out: g_free (data); return md5; }
/** * as_image_load_filename: * @image: a #AsImage instance. * @filename: filename to read from * @error: A #GError or %NULL. * * Reads a pixbuf from a file. * * NOTE: This function also sets the suggested filename which can be retrieved * using as_image_get_basename(). This can be overridden if required. * * Returns: %TRUE for success * * Since: 0.1.6 **/ gboolean as_image_load_filename (AsImage *image, const gchar *filename, GError **error) { AsImagePrivate *priv = GET_PRIVATE (image); gsize len; g_autofree gchar *basename = NULL; g_autofree gchar *data = NULL; g_autoptr(GdkPixbuf) pixbuf = NULL; /* get the contents so we can hash the predictable file data, * rather than the unpredicatable (for JPEG) pixel data */ if (!g_file_get_contents (filename, &data, &len, error)) return FALSE; g_free (priv->md5); priv->md5 = g_compute_checksum_for_data (G_CHECKSUM_MD5, (guchar * )data, len); /* load the image */ pixbuf = gdk_pixbuf_new_from_file (filename, error); if (pixbuf == NULL) return FALSE; /* set */ basename = g_path_get_basename (filename); as_image_set_basename (image, basename); as_image_set_pixbuf (image, pixbuf); return TRUE; }
static gboolean fu_provider_chug_verify (FuProvider *provider, FuDevice *device, FuProviderVerifyFlags flags, GError **error) { FuProviderChug *provider_chug = FU_PROVIDER_CHUG (provider); FuProviderChugPrivate *priv = GET_PRIVATE (provider_chug); FuProviderChugItem *item; GChecksumType checksum_type; gsize len; g_autoptr(GError) error_local = NULL; g_autofree gchar *hash = NULL; g_autofree guint8 *data = NULL; /* find item */ item = g_hash_table_lookup (priv->devices, fu_device_get_id (device)); if (item == NULL) { g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_NOT_FOUND, "cannot find: %s", fu_device_get_id (device)); return FALSE; } /* open */ if (!fu_provider_chug_open (item, error)) return FALSE; /* get the firmware from the device */ g_debug ("ColorHug: Verifying firmware"); ch_device_queue_read_firmware (priv->device_queue, item->usb_device, &data, &len); fu_provider_set_status (provider, FWUPD_STATUS_DEVICE_VERIFY); if (!ch_device_queue_process (priv->device_queue, CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE, NULL, &error_local)) { g_set_error (error, FWUPD_ERROR, FWUPD_ERROR_WRITE, "failed to dump firmware: %s", error_local->message); g_usb_device_close (item->usb_device, NULL); return FALSE; } /* get the checksum */ checksum_type = fu_provider_get_checksum_type (flags); hash = g_compute_checksum_for_data (checksum_type, (guchar *) data, len); fu_device_set_checksum (device, hash); fu_device_set_checksum_kind (device, checksum_type); /* we're done here */ if (!g_usb_device_close (item->usb_device, &error_local)) g_debug ("Failed to close: %s", error_local->message); return TRUE; }
void generate_uuid(struct connection *conn, gchar *id, guint32 id_size) { /* Make the UUID just be a hash of the SSID */ gchar *raw_id; raw_id = g_compute_checksum_for_data(G_CHECKSUM_MD5, (guchar *)conn, sizeof(*conn)); md5touuid(raw_id, id, id_size); }
void get(SoupServer *server, SoupMessage *msg, const char *path) { struct btval key, val; key.data = (void*)path+1; key.size = strlen(path)-1; key.free_data = FALSE; key.mp = NULL; g_debug ("GET\n Path=%s\n Fetching key %s", path, (char*)key.data); const struct btree_stat *stat = btree_stat(btree); show_dbstats("",stat); if (0 == btree_get(btree,&key,&val)) { g_debug ("data checksum is %s", g_compute_checksum_for_data(G_CHECKSUM_MD5, val.data, val.size)); /* we need to make the data 64 bits aligned for gvariant. Best plan is to make all data aligned in the store, but for now, lets just copy it to somewhere aligned. TODO: think about fragmentation. it may just be ok, as so far we delete everything we malloc in this function, despite the lifetimes being interleaved. */ char *buf = g_slice_alloc(val.size + 8); char *data = ALIGN_64(buf); memcpy (data, val.data, val.size); g_debug ("aligned data checksum is %s", g_compute_checksum_for_data(G_CHECKSUM_MD5, data, val.size)); GVariant *gv = g_variant_new_from_data(G_VARIANT_TYPE_VARIANT, data, val.size, TRUE, NULL, NULL); char *debug = g_variant_print (gv, TRUE); g_debug ("converted to %s", debug); g_free (debug); int length; char* ret = json_gvariant_serialize_data(gv, &length); g_variant_unref(gv); g_slice_free1 (val.size + 8, buf); soup_message_set_status (msg, SOUP_STATUS_OK); /*TODO: does soup do anything sensible with it's memory management of responses to reduce the risk of fragmentation? probably not..*/ soup_message_set_response (msg, "application/json", SOUP_MEMORY_TAKE, ret, length); } else { soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND); } }
/// Print a debug checksum message FSTATIC void _cryptframe_debug_checksum( const char * function, ///<[in] function name int lineno, ///<[in] line number const char * message, ///<[in] message const guint8* buf) ///<[in] buffer to checksum { char * checksum = g_compute_checksum_for_data(G_CHECKSUM_MD5, buf, 32); // HARDWIRED!! g_debug("%s.%d: %s [%d]%s", function, lineno, message, 32, checksum); g_free(checksum); }
static void print_md5(const char *path) { FILE *file = fopen(path, "r"); if (file == NULL) { error_log("Couldn't open %s. Error was %s", path, strerror(errno)); return; } // Get the size and other information struct stat info; if (stat(path, &info) != 0) { error_log("Couldn't open file %s; %s", path, strerror(errno)); return; } size_t size = info.st_size; if (size == 0) { unsigned char empty[512]; if (fread(empty, 512, 1, file) != 0 || feof(file) == 0) { error_log("ERROR reading %s! (It was reported as a zero size file but it didn't appear to be empty!", path); return; } info_log("Empty file OK."); } else { char *data = (char *) g_malloc(size); if (fread(data, size, 1, file) != 1) { error_log("ERROR reading %s (%s)!", path, strerror(errno)); g_free(data); fclose(file); return; } gchar *checksum = g_compute_checksum_for_data(G_CHECKSUM_MD5, (guchar *) data, size); info_log("md5: %s %s", path, checksum); g_free(checksum); g_free(data); } fclose(file); return; }
gchar * open_app_get_md5 (const gchar *str) { gchar *checksum; checksum = g_compute_checksum_for_data (G_CHECKSUM_MD5, (const guchar *) str, strlen (str)); return checksum; }
/** * Check memory using specified rsa key and signature * * arguments: * (rsa_pubkey, rsa_signature, string) * * returns: * true - if string match rsa signature * false - otherwise */ static gint lua_rsa_verify_file (lua_State *L) { RSA *rsa; rspamd_fstring_t *signature; const gchar *filename; gchar *data = NULL, *data_sig; gint ret, fd; struct stat st; rsa = lua_check_rsa_pubkey (L, 1); signature = lua_check_rsa_sign (L, 2); filename = luaL_checkstring (L, 3); if (rsa != NULL && signature != NULL && filename != NULL) { fd = open (filename, O_RDONLY); if (fd == -1) { msg_err ("cannot open file %s: %s", filename, strerror (errno)); lua_pushnil (L); } else { if (fstat (fd, &st) == -1 || (data = mmap (NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) { msg_err ("cannot mmap file %s: %s", filename, strerror (errno)); lua_pushnil (L); } else { data_sig = g_compute_checksum_for_data (G_CHECKSUM_SHA256, data, st.st_size); ret = RSA_verify (NID_sha1, data_sig, strlen (data_sig), signature->str, signature->len, rsa); if (ret == 0) { msg_info ("cannot check rsa signature for file: %s, %s", filename, ERR_error_string (ERR_get_error (), NULL)); lua_pushboolean (L, FALSE); } else { lua_pushboolean (L, TRUE); } g_free (data_sig); munmap (data, st.st_size); } close (fd); } } else { lua_pushnil (L); } return 1; }
static GstFlowReturn gst_checksum_sink_render (GstBaseSink * sink, GstBuffer * buffer) { gchar *s; s = g_compute_checksum_for_data (G_CHECKSUM_SHA1, GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer)); g_print ("%" GST_TIME_FORMAT " %s\n", GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), s); g_free (s); return GST_FLOW_OK; }
static gchar * gs_plugin_fwupd_get_file_checksum (const gchar *filename, GChecksumType checksum_type, GError **error) { gsize len; g_autofree gchar *data = NULL; if (!g_file_get_contents (filename, &data, &len, error)) { gs_utils_error_convert_gio (error); return NULL; } return g_compute_checksum_for_data (checksum_type, (const guchar *)data, len); }
static void md5_post_callback (SoupServer *server, SoupMessage *msg, const char *path, GHashTable *query, SoupClientContext *context, gpointer data) { const char *content_type; GHashTable *params; const char *fmt; char *filename, *md5sum, *redirect_uri; SoupBuffer *file; SoupURI *uri; content_type = soup_message_headers_get_content_type (msg->request_headers, NULL); if (!content_type || strcmp (content_type, "multipart/form-data") != 0) { soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST); return; } params = soup_form_decode_multipart (msg, "file", &filename, NULL, &file); if (!params) { soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST); return; } fmt = g_hash_table_lookup (params, "fmt"); md5sum = g_compute_checksum_for_data (G_CHECKSUM_MD5, (gpointer)file->data, file->length); soup_buffer_free (file); uri = soup_uri_copy (soup_message_get_uri (msg)); soup_uri_set_query_from_fields (uri, "file", filename ? filename : "", "md5sum", md5sum, "fmt", fmt ? fmt : "html", NULL); redirect_uri = soup_uri_to_string (uri, FALSE); soup_message_set_status (msg, SOUP_STATUS_SEE_OTHER); soup_message_headers_replace (msg->response_headers, "Location", redirect_uri); g_free (redirect_uri); soup_uri_free (uri); g_free (md5sum); g_free (filename); g_hash_table_destroy (params); }
static GstFlowReturn gst_checksum_sink_render (GstBaseSink * sink, GstBuffer * buffer) { gchar *s; GstMapInfo map; gst_buffer_map (buffer, &map, GST_MAP_READ); s = g_compute_checksum_for_data (G_CHECKSUM_SHA1, map.data, map.size); gst_buffer_unmap (buffer, &map); g_print ("%" GST_TIME_FORMAT " %s\n", GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), s); g_free (s); return GST_FLOW_OK; }
/* stolen from nm-applet */ static char * hash_ap (NMAccessPoint *ap) { unsigned char input[66]; GBytes *ssid; NM80211Mode mode; guint32 flags; guint32 wpa_flags; guint32 rsn_flags; memset (&input[0], 0, sizeof (input)); ssid = nm_access_point_get_ssid (ap); if (ssid) memcpy (input, g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); mode = nm_access_point_get_mode (ap); if (mode == NM_802_11_MODE_INFRA) input[32] |= (1 << 0); else if (mode == NM_802_11_MODE_ADHOC) input[32] |= (1 << 1); else input[32] |= (1 << 2); /* Separate out no encryption, WEP-only, and WPA-capable */ flags = nm_access_point_get_flags (ap); wpa_flags = nm_access_point_get_wpa_flags (ap); rsn_flags = nm_access_point_get_rsn_flags (ap); if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY) && (wpa_flags == NM_802_11_AP_SEC_NONE) && (rsn_flags == NM_802_11_AP_SEC_NONE)) input[32] |= (1 << 3); else if ( (flags & NM_802_11_AP_FLAGS_PRIVACY) && (wpa_flags == NM_802_11_AP_SEC_NONE) && (rsn_flags == NM_802_11_AP_SEC_NONE)) input[32] |= (1 << 4); else if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY) && (wpa_flags != NM_802_11_AP_SEC_NONE) && (rsn_flags != NM_802_11_AP_SEC_NONE)) input[32] |= (1 << 5); else input[32] |= (1 << 6); /* duplicate it */ memcpy (&input[33], &input[0], 32); return g_compute_checksum_for_data (G_CHECKSUM_MD5, input, sizeof (input)); }
/** * as_image_set_pixbuf: * @image: a #AsImage instance. * @pixbuf: the #GdkPixbuf, or %NULL * * Sets the image pixbuf. * * Since: 0.1.6 **/ void as_image_set_pixbuf (AsImage *image, GdkPixbuf *pixbuf) { AsImagePrivate *priv = GET_PRIVATE (image); guchar *data; guint len; g_set_object (&priv->pixbuf, pixbuf); if (pixbuf == NULL) return; if (priv->md5 == NULL) { data = gdk_pixbuf_get_pixels_with_length (pixbuf, &len); priv->md5 = g_compute_checksum_for_data (G_CHECKSUM_MD5, data, len); } priv->width = gdk_pixbuf_get_width (pixbuf); priv->height = gdk_pixbuf_get_height (pixbuf); }
static GkmCertificate* add_certificate_for_data (GkmRootsModule *self, const guchar *data, gsize n_data, const gchar *path) { GkmCertificate *cert; GkmManager *manager; gchar *hash, *unique; g_assert (GKM_IS_ROOTS_MODULE (self)); g_assert (data); g_assert (path); manager = gkm_module_get_manager (GKM_MODULE (self)); g_return_val_if_fail (manager, NULL); /* Hash the certificate */ hash = g_compute_checksum_for_data (G_CHECKSUM_MD5, data, n_data); unique = g_strdup_printf ("%s:%s", path, hash); g_free (hash); /* Try and find a certificate */ cert = GKM_CERTIFICATE (gkm_manager_find_one_by_string_property (manager, "unique", unique)); if (cert != NULL) { g_free (unique); return cert; } /* Create a new certificate object */ cert = GKM_CERTIFICATE (gkm_roots_certificate_new (GKM_MODULE (self), unique, path)); g_free (unique); if (!gkm_serializable_load (GKM_SERIALIZABLE (cert), NULL, data, n_data)) { g_message ("couldn't parse certificate(s): %s", path); g_object_unref (cert); return NULL; } /* Make the certificate show up */ gkm_object_expose (GKM_OBJECT (cert), TRUE); /* And add to our wonderful table */ g_hash_table_insert (self->certificates, cert, cert); return cert; }
/** * st_texture_cache_load_from_data: * @cache: The texture cache instance * @data: Image data in PNG, GIF, etc format * @len: length of @data * @size: Size in pixels to use for the resulting texture * @error: Return location for error * * Synchronously creates an image from @data. The image is scaled down * to fit the available width and height dimensions, but the image is * never scaled up beyond its actual size. The pixbuf is rotated * according to the associated orientation setting. * * Return value: (transfer none): A new #ClutterActor with the image data loaded if it was * generated succesfully, %NULL otherwise */ ClutterActor * st_texture_cache_load_from_data (StTextureCache *cache, const guchar *data, gsize len, int size, GError **error) { ClutterTexture *texture; CoglHandle texdata; GdkPixbuf *pixbuf; char *key; char *checksum; texture = create_default_texture (cache); clutter_actor_set_size (CLUTTER_ACTOR (texture), size, size); checksum = g_compute_checksum_for_data (G_CHECKSUM_SHA1, data, len); key = g_strdup_printf (CACHE_PREFIX_COMPRESSED_CHECKSUM "checksum=%s,size=%d", checksum, size); g_free (checksum); texdata = g_hash_table_lookup (cache->priv->keyed_cache, key); if (texdata == NULL) { pixbuf = impl_load_pixbuf_data (data, len, size, size, error); if (!pixbuf) { g_object_unref (texture); g_free (key); return NULL; } texdata = pixbuf_to_cogl_handle (pixbuf); g_object_unref (pixbuf); set_texture_cogl_texture (texture, texdata); g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texdata); } g_free (key); set_texture_cogl_texture (texture, texdata); return CLUTTER_ACTOR (texture); }
/** * st_texture_cache_load_from_raw: * @cache: a #StTextureCache * @data: (array length=len): raw pixel data * @len: the length of @data * @has_alpha: whether @data includes an alpha channel * @width: width in pixels of @data * @height: width in pixels of @data * @rowstride: rowstride of @data * @size: size of icon to return * * Creates (or retrieves from cache) an icon based on raw pixel data. * * Return value: (transfer none): a new #ClutterActor displaying a * pixbuf created from @data and the other parameters. **/ ClutterActor * st_texture_cache_load_from_raw (StTextureCache *cache, const guchar *data, gsize len, gboolean has_alpha, int width, int height, int rowstride, int size, GError **error) { ClutterTexture *texture; CoglHandle texdata; char *key; char *checksum; texture = create_default_texture (); clutter_actor_set_size (CLUTTER_ACTOR (texture), size, size); /* In theory, two images of with different width and height could have the same * pixel data and thus hash the same. (Say, a 16x16 and a 8x32 blank image.) * We ignore this for now. If anybody hits this problem they should use * GChecksum directly to compute a checksum including the width and height. */ checksum = g_compute_checksum_for_data (G_CHECKSUM_SHA1, data, len); key = g_strdup_printf (CACHE_PREFIX_RAW_CHECKSUM "checksum=%s", checksum); g_free (checksum); texdata = g_hash_table_lookup (cache->priv->keyed_cache, key); if (texdata == NULL) { texdata = cogl_texture_new_from_data (width, height, COGL_TEXTURE_NONE, has_alpha ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888, COGL_PIXEL_FORMAT_ANY, rowstride, data); g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texdata); } g_free (key); set_texture_cogl_texture (texture, texdata); return CLUTTER_ACTOR (texture); }
void post(SoupServer *server, SoupMessage *msg, const char *path) { JsonParser *parser = json_parser_new (); GError *err = NULL; g_debug("POST\n path= %s\nbody = '%s'", path, msg->request_body->data); if (json_parser_load_from_data (parser, msg->request_body->data, -1, &err)) { g_debug("parsed sucessfully"); GVariant *gv = json_gvariant_deserialize(json_parser_get_root(parser), NULL, NULL); if (gv) { char *debug = g_variant_print (gv, TRUE); g_debug ("converted to %s", debug); g_free (debug); //We need to store the signature, so package in a v GVariant *packaged = g_variant_new_variant(gv); struct btval key; key.data = (void*)path+1; key.size = strlen(path)-1; key.free_data = FALSE; key.mp = NULL; struct btval val; val.data =(void*) g_variant_get_data(packaged); val.size = g_variant_get_size(packaged); val.free_data = FALSE; val.mp = NULL; g_debug ("inserting with key %s", (char*)key.data); g_debug ("data checksum is %s", g_compute_checksum_for_data(G_CHECKSUM_MD5, val.data, val.size)); int success = btree_put(btree, &key, &val,0); if (0!=success) { g_debug("put failed: %s)", strerror(errno)); } g_variant_unref (packaged); g_variant_unref (gv); } } else { g_debug("failed to parse json: %s", err->message); g_error_free(err); } soup_message_set_status (msg, SOUP_STATUS_OK); }
static gboolean as_store_cab_verify_checksum_fw (AsChecksum *checksum, const gchar *tmp_path, GError **error) { g_autofree gchar *rel_basename = NULL; g_autofree gchar *rel_fn = NULL; g_autofree gchar *actual = NULL; /* get the firmware filename */ rel_basename = g_path_get_basename (as_checksum_get_filename (checksum)); rel_fn = g_build_filename (tmp_path, rel_basename, NULL); /* calculate checksum */ if (g_file_test (rel_fn, G_FILE_TEST_EXISTS)) { gsize len; g_autofree gchar *data = NULL; if (!g_file_get_contents (rel_fn, &data, &len, error)) return FALSE; actual = g_compute_checksum_for_data (G_CHECKSUM_SHA1, (guchar *)data, len); } /* nothing already set, so just add */ if (as_checksum_get_value (checksum) == NULL) { as_checksum_set_kind (checksum, G_CHECKSUM_SHA1); as_checksum_set_value (checksum, actual); return TRUE; } /* check it matches */ if (g_strcmp0 (actual, as_checksum_get_value (checksum)) != 0) { g_set_error (error, AS_STORE_ERROR, AS_STORE_ERROR_FAILED, "contents checksum invalid, expected %s, got %s", as_checksum_get_value (checksum), actual); return FALSE; } /* success */ return TRUE; }
/** * as_image_set_pixbuf: * @image: a #AsImage instance. * @pixbuf: the #GdkPixbuf, or %NULL * * Sets the image pixbuf. * * Since: 0.1.6 **/ void as_image_set_pixbuf (AsImage *image, GdkPixbuf *pixbuf) { AsImagePrivate *priv = GET_PRIVATE (image); guchar *data; guint len; g_set_object (&priv->pixbuf, pixbuf); if (pixbuf == NULL) return; if (priv->md5 == NULL) { g_autofree gchar *md5_tmp = NULL; data = gdk_pixbuf_get_pixels_with_length (pixbuf, &len); md5_tmp = g_compute_checksum_for_data (G_CHECKSUM_MD5, data, len); as_ref_string_assign_safe (&priv->md5, md5_tmp); } priv->width = (guint) gdk_pixbuf_get_width (pixbuf); priv->height = (guint) gdk_pixbuf_get_height (pixbuf); }
/* Borrowed from network-manager-applet src/utils/utils.c */ char * utils_hash_ap (const GByteArray *ssid, NM80211Mode mode, guint32 flags, guint32 wpa_flags, guint32 rsn_flags) { unsigned char input[66]; memset (&input[0], 0, sizeof (input)); if (ssid) memcpy (input, ssid->data, ssid->len); if (mode == NM_802_11_MODE_INFRA) input[32] |= (1 << 0); else if (mode == NM_802_11_MODE_ADHOC) input[32] |= (1 << 1); else input[32] |= (1 << 2); /* Separate out no encryption, WEP-only, and WPA-capable */ if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY) && (wpa_flags == NM_802_11_AP_SEC_NONE) && (rsn_flags == NM_802_11_AP_SEC_NONE)) input[32] |= (1 << 3); else if ( (flags & NM_802_11_AP_FLAGS_PRIVACY) && (wpa_flags == NM_802_11_AP_SEC_NONE) && (rsn_flags == NM_802_11_AP_SEC_NONE)) input[32] |= (1 << 4); else if ( !(flags & NM_802_11_AP_FLAGS_PRIVACY) && (wpa_flags != NM_802_11_AP_SEC_NONE) && (rsn_flags != NM_802_11_AP_SEC_NONE)) input[32] |= (1 << 5); else input[32] |= (1 << 6); /* duplicate it */ memcpy (&input[33], &input[0], 32); return g_compute_checksum_for_data (G_CHECKSUM_MD5, input, sizeof (input)); }
/** * st_texture_cache_load_from_raw: * @cache: a #StTextureCache * @data: raw pixel data * @len: the length of @data * @has_alpha: whether @data includes an alpha channel * @width: width in pixels of @data * @height: width in pixels of @data * @rowstride: rowstride of @data * @size: size of icon to return * * Creates (or retrieves from cache) an icon based on raw pixel data. * * Return value: (transfer none): a new #ClutterActor displaying a * pixbuf created from @data and the other parameters. **/ ClutterActor * st_texture_cache_load_from_raw (StTextureCache *cache, const guchar *data, gsize len, gboolean has_alpha, int width, int height, int rowstride, int size, GError **error) { ClutterTexture *texture; CoglHandle texdata; char *key; char *checksum; texture = create_default_texture (cache); clutter_actor_set_size (CLUTTER_ACTOR (texture), size, size); /* In theory, two images of different size could have the same * pixel data. We ignore that theory. */ checksum = g_compute_checksum_for_data (G_CHECKSUM_SHA1, data, len); key = g_strdup_printf (CACHE_PREFIX_RAW_CHECKSUM "checksum=%s,size=%d", checksum, size); g_free (checksum); texdata = g_hash_table_lookup (cache->priv->keyed_cache, key); if (texdata == NULL) { texdata = cogl_texture_new_from_data (width, height, COGL_TEXTURE_NONE, has_alpha ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888, COGL_PIXEL_FORMAT_ANY, rowstride, data); g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texdata); } g_free (key); set_texture_cogl_texture (texture, texdata); return CLUTTER_ACTOR (texture); }
static void digest_pem_block (GQuark type, GBytes *data, GBytes *outer, GHashTable *headers, gpointer user_data) { gchar **result = (gchar**)user_data; g_assert (result); if (!is_private_key_type (type)) return; /* Only digest the first key in the file */ if (*result != NULL) return; *result = g_compute_checksum_for_data (G_CHECKSUM_SHA1, g_bytes_get_data (data, NULL), g_bytes_get_size (data)); }
static void server_callback (SoupServer *server, SoupMessage *msg, const char *path, GHashTable *query, SoupClientContext *context, gpointer data) { SoupMessageBody *md5_body; char *md5; if (g_str_has_prefix (path, "/redirect")) { soup_message_set_status (msg, SOUP_STATUS_FOUND); soup_message_headers_replace (msg->response_headers, "Location", "/"); return; } if (msg->method == SOUP_METHOD_GET) { soup_message_set_response (msg, "text/plain", SOUP_MEMORY_STATIC, "three\r\ntwo\r\none\r\n", strlen ("three\r\ntwo\r\none\r\n")); soup_buffer_free (soup_message_body_flatten (msg->response_body)); md5_body = msg->response_body; soup_message_set_status (msg, SOUP_STATUS_OK); } else if (msg->method == SOUP_METHOD_PUT) { soup_message_set_status (msg, SOUP_STATUS_CREATED); md5_body = msg->request_body; } else { soup_message_set_status (msg, SOUP_STATUS_METHOD_NOT_ALLOWED); return; } md5 = g_compute_checksum_for_data (G_CHECKSUM_MD5, (guchar *)md5_body->data, md5_body->length); soup_message_headers_append (msg->response_headers, "Content-MD5", md5); g_free (md5); }
static void purple_smiley_set_property(GObject *object, guint param_id, const GValue *value, GParamSpec *spec) { PurpleSmiley *smiley = PURPLE_SMILEY(object); PurpleSmileyPrivate *priv = PURPLE_SMILEY_GET_PRIVATE(smiley); switch (param_id) { case PROP_SHORTCUT: { const char *shortcut = g_value_get_string(value); purple_smiley_set_shortcut(smiley, shortcut); } break; case PROP_IMGSTORE: { PurpleStoredImage *img = g_value_get_pointer(value); purple_imgstore_unref(priv->img); g_free(priv->checksum); priv->img = img; if (img) { priv->checksum = g_compute_checksum_for_data( G_CHECKSUM_SHA1, purple_imgstore_get_data(img), purple_imgstore_get_size(img)); purple_smiley_data_store(img); } else { priv->checksum = NULL; } } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, spec); break; } }
static void store_object_hash (GkmMate2Storage *self, GkmTransaction *transaction, const gchar *identifier, const guchar *data, gsize n_data) { GkmDataResult res; gchar *digest; g_assert (GKM_IS_MATE2_STORAGE (self)); g_assert (GKM_IS_TRANSACTION (transaction)); g_assert (identifier); g_assert (data); digest = g_compute_checksum_for_data (G_CHECKSUM_SHA1, data, n_data); if (digest == NULL) { gkm_transaction_fail (transaction, CKR_GENERAL_ERROR); g_return_if_reached (); } res = gkm_mate2_file_write_value (self->file, identifier, CKA_MATE_INTERNAL_SHA1, digest, strlen (digest)); g_free (digest); if (res != GKM_DATA_SUCCESS) gkm_transaction_fail (transaction, CKR_GENERAL_ERROR); }