Skip to content

Instantly share code, notes, and snippets.

defmodule ErlangLogger do
@moduledoc """
Designed to mirror [`kernel/include/logger.hrl`](https://github.com/erlang/otp/blob/da166b76de977171243dd2ea7f86b98f451fabc5/lib/kernel/include/logger.hrl)
*WARNING:* Currently blows up if `__CALLER__` does not have a valid `mfa`
"""
defmacro log_emergency(a) do
do_log(:emergency, [a], __CALLER__)
end
defmodule ExampleEncryptor do
def encrypt(plain_text, password) do
salt = :crypto.strong_rand_bytes(32)
iterations = 4096
kek = derive_key_encryption_key(password, salt, iterations, 32, :sha512)
kiv = :crypto.strong_rand_bytes(12)
cek = :crypto.strong_rand_bytes(32)
civ = :crypto.strong_rand_bytes(12)
{cek_cipher_text, cek_cipher_tag} = :crypto.block_encrypt(:aes_gcm, kek, kiv, {<<>>, cek})

The following module can be placed in the root level of elixir-lang/elixir and executed using the following:

bin/elixirc keyword_delete_bench.ex && erl -noshell -pa . -pa lib/elixir/ebin -s 'keyword_delete_bench'

Example (minimized output):

## count=100000, size=10

There's something out of whack with the consistent hash algorithm used by swarm (libring):

Add 4 nodes all weighted equally (should be 4 x 25%) libring

iex> ring = HashRing.new()
iex> ring = HashRing.add_node(ring, :a@nohost)
iex> ring = HashRing.add_node(ring, :b@nohost)
iex> ring = HashRing.add_node(ring, :c@nohost)
iex&gt; ring = HashRing.add_node(ring, :d@nohost)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
crc_3_gsm
crc_3_rohc
crc_4_interlaken
crc_4_itu
crc_5
crc_5_epc
crc_5_itu
crc_5_usb
crc_6_cdma2000_a
crc_6_cdma2000_b
@potatosalad
potatosalad / results.txt
Last active August 31, 2017 19:26
Possible issue with AC binary split
=== Test case: binary_module_SUITE:random_ref_sr_comp/1 (click for source code)
=== Config value:
[{watchdog,<0.222.0>},
{tc_logfile,"/home/andrew/otp/release/tests/test_server/ct_run.test_server@antergos.2017-08-31_09.57.16/tests.stdlib_test.binary_module_SUITE.logs/run.2017-08-31_10.03.13/binary_module_suite.random_ref_sr_comp.html"},
{tc_group_properties,[{suite,binary_module_SUITE}]},
{tc_group_path,[]},
{data_dir,"/home/andrew/otp/release/tests/stdlib_test/binary_module_SUITE_data/"},
{priv_dir,"/home/andrew/otp/release/tests/test_server/ct_run.test_server@antergos.2017-08-31_09.57.16/tests.stdlib_test.binary_module_SUITE.logs/run.2017-08-31_10.03.13/log_private/"},
@potatosalad
potatosalad / iam_assert.erl
Last active August 24, 2017 17:10
Snippets from unreleased IAM erlang library
%% -*- mode: erlang; tab-width: 4; indent-tabs-mode: 1; st-rulers: [70] -*-
%% vim: ts=4 sw=4 ft=erlang noet
%%%-------------------------------------------------------------------
%%% @author Andrew Bennett <andrew@pixid.com>
%%% @copyright 2017, Andrew Bennett
%%% @doc
%%%
%%% @end
%%% Created : 24 Apr 2017 by Andrew Bennett <andrew@pixid.com>
%%%-------------------------------------------------------------------

So, the jose library needs a little work done to separate the ES (Ephemeral-Static) and SS (Static-Static) operations.

The JWA RFC 7518 only defines ES operations and actually states (https://tools.ietf.org/html/rfc7518#section-4.6):

A new ephemeral public key value MUST be generated for each key agreement operation.

The separate modes of operation were clarified by a different working group, COSE WG, in RFC 8152 (https://tools.ietf.org/html/rfc8152#section-12.4):

Ephemeral-Static (ES) DH: where the sender of the message creates a one-time DH key and uses a static key for the recipient. The

Run in shell with:

erlc bench_binary_find.erl && erl -noshell -pa . -s bench_binary_find
Erlang/OTP 20 (master, unpatched)

binary:split/3 is up to 80x slower than a tail recursion calling binary:split/2 multiple times.