Comments (6)
it is unlikely it is the intent because it mix all the characters.
This actually is the intent, because the lists that we end up with are usually not unique in their sorting and order, but the combined mixture of characters is exactly the same.
The one exception being when an IP address from an upstream record having changed, which is when we email out a diff.
from sender_policy_flattener.
You can see example below. I ran the script 5 times and tried all the methods you suggested.
Note how different the records become after the first SPF record when they are kept as regular lists or json:
# ''.join(sorted(iterable))
v=spf1 ip4:17.0.0.0/8 ip4:23.253.182.0/23 ip4:50.23.218.192/27 ip4:52.205.61.79 ip4:54.172.97.247 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:104.130.96.0/28 ip4:104.130.122.0/23 ip4:108.177.8.0/21 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:173.193.210.32/27 ip4:173.194.0.0/16 ip4:174.37.226.64/27 ip4:174.129.203.189 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:192.237.158.0/23 ip4:198.61.254.0/23 include:spf1.mydomain.com -allv=spf1 ip4:216.239.32.0/19 ip6:2404:6800:4000::/36 ip4:208.43.239.136/30 ip6:2607:f8b0:4000::/36 ip4:216.58.192.0/19 ip6:2800:3f0:4000::/36 ip4:209.61.151.0/24 ip4:209.85.128.0/17 ip6:2001:4860:4000::/36 ip6:2a00:1450:4000::/36 ip4:207.126.144.0/20 ip6:2c0f:fb50:4000::/36 -all
v=spf1 ip4:17.0.0.0/8 ip4:23.253.182.0/23 ip4:50.23.218.192/27 ip4:52.205.61.79 ip4:54.172.97.247 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:104.130.96.0/28 ip4:104.130.122.0/23 ip4:108.177.8.0/21 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:173.193.210.32/27 ip4:173.194.0.0/16 ip4:174.37.226.64/27 ip4:174.129.203.189 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:192.237.158.0/23 ip4:198.61.254.0/23 include:spf1.mydomain.com -allv=spf1 ip6:2800:3f0:4000::/36 ip4:216.239.32.0/19 ip4:208.43.239.136/30 ip6:2a00:1450:4000::/36 ip4:216.58.192.0/19 ip6:2607:f8b0:4000::/36 ip4:207.126.144.0/20 ip6:2c0f:fb50:4000::/36 ip4:209.61.151.0/24 ip6:2001:4860:4000::/36 ip6:2404:6800:4000::/36 ip4:209.85.128.0/17 -all
v=spf1 ip4:17.0.0.0/8 ip4:23.253.182.0/23 ip4:50.23.218.192/27 ip4:52.205.61.79 ip4:54.172.97.247 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:104.130.96.0/28 ip4:104.130.122.0/23 ip4:108.177.8.0/21 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:173.193.210.32/27 ip4:173.194.0.0/16 ip4:174.37.226.64/27 ip4:174.129.203.189 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:192.237.158.0/23 ip4:198.61.254.0/23 include:spf1.mydomain.com -allv=spf1 ip6:2001:4860:4000::/36 ip6:2c0f:fb50:4000::/36 ip6:2800:3f0:4000::/36 ip4:209.61.151.0/24 ip4:209.85.128.0/17 ip6:2a00:1450:4000::/36 ip6:2404:6800:4000::/36 ip6:2607:f8b0:4000::/36 ip4:216.58.192.0/19 ip4:216.239.32.0/19 ip4:208.43.239.136/30 ip4:207.126.144.0/20 -all
v=spf1 ip4:17.0.0.0/8 ip4:23.253.182.0/23 ip4:50.23.218.192/27 ip4:52.205.61.79 ip4:54.172.97.247 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:104.130.96.0/28 ip4:104.130.122.0/23 ip4:108.177.8.0/21 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:173.193.210.32/27 ip4:173.194.0.0/16 ip4:174.37.226.64/27 ip4:174.129.203.189 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:192.237.158.0/23 ip4:198.61.254.0/23 include:spf1.mydomain.com -allv=spf1 ip4:216.58.192.0/19 ip6:2607:f8b0:4000::/36 ip4:209.85.128.0/17 ip6:2404:6800:4000::/36 ip4:209.61.151.0/24 ip4:216.239.32.0/19 ip4:208.43.239.136/30 ip6:2800:3f0:4000::/36 ip6:2c0f:fb50:4000::/36 ip6:2001:4860:4000::/36 ip6:2a00:1450:4000::/36 ip4:207.126.144.0/20 -all
v=spf1 ip4:17.0.0.0/8 ip4:23.253.182.0/23 ip4:50.23.218.192/27 ip4:52.205.61.79 ip4:54.172.97.247 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:104.130.96.0/28 ip4:104.130.122.0/23 ip4:108.177.8.0/21 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:173.193.210.32/27 ip4:173.194.0.0/16 ip4:174.37.226.64/27 ip4:174.129.203.189 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:192.237.158.0/23 ip4:198.61.254.0/23 include:spf1.mydomain.com -allv=spf1 ip4:216.58.192.0/19 ip4:208.43.239.136/30 ip6:2607:f8b0:4000::/36 ip4:209.61.151.0/24 ip4:207.126.144.0/20 ip6:2001:4860:4000::/36 ip6:2a00:1450:4000::/36 ip4:209.85.128.0/17 ip6:2404:6800:4000::/36 ip6:2c0f:fb50:4000::/36 ip4:216.239.32.0/19 ip6:2800:3f0:4000::/36 -all
# json.dumps(sorted(iterable))
["v=spf1 ip4:17.0.0.0/8 ip4:23.253.182.0/23 ip4:50.23.218.192/27 ip4:52.205.61.79 ip4:54.172.97.247 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:104.130.96.0/28 ip4:104.130.122.0/23 ip4:108.177.8.0/21 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:173.193.210.32/27 ip4:173.194.0.0/16 ip4:174.37.226.64/27 ip4:174.129.203.189 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:192.237.158.0/23 ip4:198.61.254.0/23 include:spf1.mydomain.com -all", "v=spf1 ip4:216.239.32.0/19 ip6:2404:6800:4000::/36 ip4:208.43.239.136/30 ip6:2607:f8b0:4000::/36 ip4:216.58.192.0/19 ip6:2800:3f0:4000::/36 ip4:209.61.151.0/24 ip4:209.85.128.0/17 ip6:2001:4860:4000::/36 ip6:2a00:1450:4000::/36 ip4:207.126.144.0/20 ip6:2c0f:fb50:4000::/36 -all"]
["v=spf1 ip4:17.0.0.0/8 ip4:23.253.182.0/23 ip4:50.23.218.192/27 ip4:52.205.61.79 ip4:54.172.97.247 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:104.130.96.0/28 ip4:104.130.122.0/23 ip4:108.177.8.0/21 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:173.193.210.32/27 ip4:173.194.0.0/16 ip4:174.37.226.64/27 ip4:174.129.203.189 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:192.237.158.0/23 ip4:198.61.254.0/23 include:spf1.mydomain.com -all", "v=spf1 ip6:2800:3f0:4000::/36 ip4:216.239.32.0/19 ip4:208.43.239.136/30 ip6:2a00:1450:4000::/36 ip4:216.58.192.0/19 ip6:2607:f8b0:4000::/36 ip4:207.126.144.0/20 ip6:2c0f:fb50:4000::/36 ip4:209.61.151.0/24 ip6:2001:4860:4000::/36 ip6:2404:6800:4000::/36 ip4:209.85.128.0/17 -all"]
["v=spf1 ip4:17.0.0.0/8 ip4:23.253.182.0/23 ip4:50.23.218.192/27 ip4:52.205.61.79 ip4:54.172.97.247 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:104.130.96.0/28 ip4:104.130.122.0/23 ip4:108.177.8.0/21 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:173.193.210.32/27 ip4:173.194.0.0/16 ip4:174.37.226.64/27 ip4:174.129.203.189 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:192.237.158.0/23 ip4:198.61.254.0/23 include:spf1.mydomain.com -all", "v=spf1 ip6:2001:4860:4000::/36 ip6:2c0f:fb50:4000::/36 ip6:2800:3f0:4000::/36 ip4:209.61.151.0/24 ip4:209.85.128.0/17 ip6:2a00:1450:4000::/36 ip6:2404:6800:4000::/36 ip6:2607:f8b0:4000::/36 ip4:216.58.192.0/19 ip4:216.239.32.0/19 ip4:208.43.239.136/30 ip4:207.126.144.0/20 -all"]
["v=spf1 ip4:17.0.0.0/8 ip4:23.253.182.0/23 ip4:50.23.218.192/27 ip4:52.205.61.79 ip4:54.172.97.247 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:104.130.96.0/28 ip4:104.130.122.0/23 ip4:108.177.8.0/21 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:173.193.210.32/27 ip4:173.194.0.0/16 ip4:174.37.226.64/27 ip4:174.129.203.189 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:192.237.158.0/23 ip4:198.61.254.0/23 include:spf1.mydomain.com -all", "v=spf1 ip4:216.58.192.0/19 ip6:2607:f8b0:4000::/36 ip4:209.85.128.0/17 ip6:2404:6800:4000::/36 ip4:209.61.151.0/24 ip4:216.239.32.0/19 ip4:208.43.239.136/30 ip6:2800:3f0:4000::/36 ip6:2c0f:fb50:4000::/36 ip6:2001:4860:4000::/36 ip6:2a00:1450:4000::/36 ip4:207.126.144.0/20 -all"]
["v=spf1 ip4:17.0.0.0/8 ip4:23.253.182.0/23 ip4:50.23.218.192/27 ip4:52.205.61.79 ip4:54.172.97.247 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:104.130.96.0/28 ip4:104.130.122.0/23 ip4:108.177.8.0/21 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:173.193.210.32/27 ip4:173.194.0.0/16 ip4:174.37.226.64/27 ip4:174.129.203.189 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:192.237.158.0/23 ip4:198.61.254.0/23 include:spf1.mydomain.com -all", "v=spf1 ip4:216.58.192.0/19 ip4:208.43.239.136/30 ip6:2607:f8b0:4000::/36 ip4:209.61.151.0/24 ip4:207.126.144.0/20 ip6:2001:4860:4000::/36 ip6:2a00:1450:4000::/36 ip4:209.85.128.0/17 ip6:2404:6800:4000::/36 ip6:2c0f:fb50:4000::/36 ip4:216.239.32.0/19 ip6:2800:3f0:4000::/36 -all"]
# hashlib.sha256(''.join(sorted(''.join(sorted(iterable)))).encode()).hexdigest()
bc479a4aa72fbe7a8a7d4b6c7d11ab4d0aa49cca6e9ced3a6f84d8b16b0f2508
bc479a4aa72fbe7a8a7d4b6c7d11ab4d0aa49cca6e9ced3a6f84d8b16b0f2508
bc479a4aa72fbe7a8a7d4b6c7d11ab4d0aa49cca6e9ced3a6f84d8b16b0f2508
bc479a4aa72fbe7a8a7d4b6c7d11ab4d0aa49cca6e9ced3a6f84d8b16b0f2508
bc479a4aa72fbe7a8a7d4b6c7d11ab4d0aa49cca6e9ced3a6f84d8b16b0f2508
# ''.join(sorted(''.join(sorted(iterable)))
--............................................................................................/////////////////////////////////000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222222333333333333333333333333333333333344444444444444444444444444444444444444444444444444444444444444555555555555555666666666666666666666666666666666666677777777777777777777777777888888888888888888888888999999999999999999999:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::==aaaabbcccddefffffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiilllllmmmnnoopppppppppppppppppppppppppppppppppppppppsssuvvy
--............................................................................................/////////////////////////////////000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222222333333333333333333333333333333333344444444444444444444444444444444444444444444444444444444444444555555555555555666666666666666666666666666666666666677777777777777777777777777888888888888888888888888999999999999999999999:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::==aaaabbcccddefffffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiilllllmmmnnoopppppppppppppppppppppppppppppppppppppppsssuvvy
--............................................................................................/////////////////////////////////000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222222333333333333333333333333333333333344444444444444444444444444444444444444444444444444444444444444555555555555555666666666666666666666666666666666666677777777777777777777777777888888888888888888888888999999999999999999999:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::==aaaabbcccddefffffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiilllllmmmnnoopppppppppppppppppppppppppppppppppppppppsssuvvy
--............................................................................................/////////////////////////////////000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222222333333333333333333333333333333333344444444444444444444444444444444444444444444444444444444444444555555555555555666666666666666666666666666666666666677777777777777777777777777888888888888888888888888999999999999999999999:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::==aaaabbcccddefffffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiilllllmmmnnoopppppppppppppppppppppppppppppppppppppppsssuvvy
--............................................................................................/////////////////////////////////000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111122222222222222222222222222222222222222222222222222222222222222222333333333333333333333333333333333344444444444444444444444444444444444444444444444444444444444444555555555555555666666666666666666666666666666666666677777777777777777777777777888888888888888888888888999999999999999999999:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::==aaaabbcccddefffffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiilllllmmmnnoopppppppppppppppppppppppppppppppppppppppsssuvvy
from sender_policy_flattener.
with an example it's easier to understand your aim
example_spf_records="""v=spf1 ip4:17.0.0.0/8 ip4:23.253.182.0/23 ip4:50.23.218.192/27 ip4:52.205.61.79 ip4:54.172.97.247 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:104.130.96.0/28 ip4:104.130.122.0/23 ip4:108.177.8.0/21 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:173.193.210.32/27 ip4:173.194.0.0/16 ip4:174.37.226.64/27 ip4:174.129.203.189 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:192.237.158.0/23 ip4:198.61.254.0/23 include:spf1.mydomain.com -allv=spf1 ip4:216.239.32.0/19 ip6:2404:6800:4000::/36 ip4:208.43.239.136/30 ip6:2607:f8b0:4000::/36 ip4:216.58.192.0/19 ip6:2800:3f0:4000::/36 ip4:209.61.151.0/24 ip4:209.85.128.0/17 ip6:2001:4860:4000::/36 ip6:2a00:1450:4000::/36 ip4:207.126.144.0/20 ip6:2c0f:fb50:4000::/36 -all
v=spf1 ip4:17.0.0.0/8 ip4:23.253.182.0/23 ip4:50.23.218.192/27 ip4:52.205.61.79 ip4:54.172.97.247 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:104.130.96.0/28 ip4:104.130.122.0/23 ip4:108.177.8.0/21 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:173.193.210.32/27 ip4:173.194.0.0/16 ip4:174.37.226.64/27 ip4:174.129.203.189 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:192.237.158.0/23 ip4:198.61.254.0/23 include:spf1.mydomain.com -allv=spf1 ip6:2800:3f0:4000::/36 ip4:216.239.32.0/19 ip4:208.43.239.136/30 ip6:2a00:1450:4000::/36 ip4:216.58.192.0/19 ip6:2607:f8b0:4000::/36 ip4:207.126.144.0/20 ip6:2c0f:fb50:4000::/36 ip4:209.61.151.0/24 ip6:2001:4860:4000::/36 ip6:2404:6800:4000::/36 ip4:209.85.128.0/17 -all
v=spf1 ip4:17.0.0.0/8 ip4:23.253.182.0/23 ip4:50.23.218.192/27 ip4:52.205.61.79 ip4:54.172.97.247 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:104.130.96.0/28 ip4:104.130.122.0/23 ip4:108.177.8.0/21 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:173.193.210.32/27 ip4:173.194.0.0/16 ip4:174.37.226.64/27 ip4:174.129.203.189 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:192.237.158.0/23 ip4:198.61.254.0/23 include:spf1.mydomain.com -allv=spf1 ip6:2001:4860:4000::/36 ip6:2c0f:fb50:4000::/36 ip6:2800:3f0:4000::/36 ip4:209.61.151.0/24 ip4:209.85.128.0/17 ip6:2a00:1450:4000::/36 ip6:2404:6800:4000::/36 ip6:2607:f8b0:4000::/36 ip4:216.58.192.0/19 ip4:216.239.32.0/19 ip4:208.43.239.136/30 ip4:207.126.144.0/20 -all
v=spf1 ip4:17.0.0.0/8 ip4:23.253.182.0/23 ip4:50.23.218.192/27 ip4:52.205.61.79 ip4:54.172.97.247 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:104.130.96.0/28 ip4:104.130.122.0/23 ip4:108.177.8.0/21 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:173.193.210.32/27 ip4:173.194.0.0/16 ip4:174.37.226.64/27 ip4:174.129.203.189 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:192.237.158.0/23 ip4:198.61.254.0/23 include:spf1.mydomain.com -allv=spf1 ip4:216.58.192.0/19 ip6:2607:f8b0:4000::/36 ip4:209.85.128.0/17 ip6:2404:6800:4000::/36 ip4:209.61.151.0/24 ip4:216.239.32.0/19 ip4:208.43.239.136/30 ip6:2800:3f0:4000::/36 ip6:2c0f:fb50:4000::/36 ip6:2001:4860:4000::/36 ip6:2a00:1450:4000::/36 ip4:207.126.144.0/20 -all
v=spf1 ip4:17.0.0.0/8 ip4:23.253.182.0/23 ip4:50.23.218.192/27 ip4:52.205.61.79 ip4:54.172.97.247 ip4:64.18.0.0/20 ip4:64.233.160.0/19 ip4:66.102.0.0/20 ip4:66.249.80.0/20 ip4:72.14.192.0/18 ip4:74.125.0.0/16 ip4:104.130.96.0/28 ip4:104.130.122.0/23 ip4:108.177.8.0/21 ip4:166.78.68.0/22 ip4:172.217.0.0/19 ip4:173.193.210.32/27 ip4:173.194.0.0/16 ip4:174.37.226.64/27 ip4:174.129.203.189 ip4:184.173.105.0/24 ip4:184.173.153.0/24 ip4:192.237.158.0/23 ip4:198.61.254.0/23 include:spf1.mydomain.com -allv=spf1 ip4:216.58.192.0/19 ip4:208.43.239.136/30 ip6:2607:f8b0:4000::/36 ip4:209.61.151.0/24 ip4:207.126.144.0/20 ip6:2001:4860:4000::/36 ip6:2a00:1450:4000::/36 ip4:209.85.128.0/17 ip6:2404:6800:4000::/36 ip6:2c0f:fb50:4000::/36 ip4:216.239.32.0/19 ip6:2800:3f0:4000::/36 -all""".split("\n")
If I take your example, all looks perfect
def original_normalization(iterable):
return ''.join(sorted(''.join(sorted(iterable))))
#print(example_spf_records)
assert 1 == len(set(original_normalization(spf) for spf in example_spf_records))
It's because your example is random enough to not create collision
but if you take an adversiorary example
problematics_spf = ["v=spf1 1.2.3.4/24 -all","v=spf1 1.2.4.3/24 -all"]
It says that both spf are same because they contain same characters
assert 1 == len(set(original_normalization(spf) for spf in problematics_spf))
Now that I understood what is your problematic, I can make a constructive proposition
def sorted_spf(spf):
return ' '.join(sorted(spf.split()))
and both test case makes the expected result
assert 1 == len(set(sorted_spf(spf) for spf in example_spf_records))
assert 2 == len(set(sorted_spf(spf) for spf in problematics_spf))
The exact function might be different depending on which is the input but I suppose you have the idea now
from sender_policy_flattener.
I see what you mean now, but I can't think of a way to get around that problem.
The only way I could simplify the code was with ''.join(sorted(str(iterable)))
, but that still might end up in a collision given a small enough list of addresses.
from sender_policy_flattener.
Alright I think I got something going that avoids the collision:
def hash_seq(iterable):
""" Acts as a centrifuge for our SPF records and returns a hash """
squashed_sequence = ' '.join(sorted([token for string in iterable for token in string.split()]))
with open('test', 'a+') as f:
f.seek(0)
lines = f.readlines()
if len(lines):
assert len(set(lines)) == 1
f.write(squashed_sequence + '\n')
return hashlib.sha256(squashed_sequence.encode()).hexdigest()
from sender_policy_flattener.
This has been updated now
from sender_policy_flattener.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sender_policy_flattener.