From 658899419ce79e301237b9ea75c55d411b8d3316 Mon Sep 17 00:00:00 2001
From: Daniel Czerwonk <daniel@dan-nrw.de>
Date: Tue, 26 Jun 2018 13:45:07 +0200
Subject: [PATCH] addressed review comments

---
 route/bgp_path.go | 11 ++++++-----
 route/bgp_test.go |  4 ++--
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/route/bgp_path.go b/route/bgp_path.go
index bd42ac3b..6fd0eb32 100644
--- a/route/bgp_path.go
+++ b/route/bgp_path.go
@@ -172,8 +172,12 @@ func (b *BGPPath) Prepend(asn uint32, times uint16) {
 		return
 	}
 
+	if len(b.ASPath) == 0 {
+		b.insertNewASSequence()
+	}
+
 	first := b.ASPath[0]
-	if len(b.ASPath) == 0 || first.Type == packet.ASSet {
+	if first.Type == packet.ASSet {
 		b.insertNewASSequence()
 	}
 
@@ -228,11 +232,8 @@ func (b *BGPPath) ComputeHash() string {
 		b.LargeCommunities,
 		b.PathIdentifier)
 
-	r := strings.NewReader(s)
 	h := sha256.New()
-	r.WriteTo(h)
-
-	return fmt.Sprintf("%x", h.Sum(nil))
+	return fmt.Sprintf("%x", h.Sum([]byte(s)))
 }
 
 // CommunitiesString returns the formated communities
diff --git a/route/bgp_test.go b/route/bgp_test.go
index 2eb017c2..23a7126d 100644
--- a/route/bgp_test.go
+++ b/route/bgp_test.go
@@ -36,9 +36,9 @@ func TestComputeHash(t *testing.T) {
 		Source:         4,
 	}
 
-	assert.Equal(t, "45e238420552b88043edb8cb402034466b08d53b49f8e0fedc680747014ddeff", p.ComputeHash())
+	assert.Equal(t, "313030093130300931323320343536093009310966616c736509310934095b313233203435365d095b7b33203120327d5d0935e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", p.ComputeHash())
 
 	p.LocalPref = 150
 
-	assert.NotEqual(t, "45e238420552b88043edb8cb402034466b08d53b49f8e0fedc680747014ddeff", p.ComputeHash())
+	assert.NotEqual(t, "313030093130300931323320343536093009310966616c736509310934095b313233203435365d095b7b33203120327d5d0935e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", p.ComputeHash())
 }
-- 
GitLab