Procházet zdrojové kódy

finish secure.go

secure2
kidjung před 4 roky
rodič
revize
a3a11f1479
3 změnil soubory, kde provedl 51 přidání a 46 odebrání
  1. 0
    37
      modules/matching_test.go
  2. 2
    1
      modules/message.go
  3. 49
    8
      modules/secure.go

+ 0
- 37
modules/matching_test.go Zobrazit soubor

@@ -1,37 +0,0 @@
1
-package modules
2
-
3
-import (
4
-	"fmt"
5
-	"testing"
6
-)
7
-
8
-func Test_simpleLList_pbNtraverse(t *testing.T) {
9
-	mylist := new(LList)
10
-	mylist.PushBack(30)
11
-	mylist.PushBack(40)
12
-	mylist.PushBack(20)
13
-	mylist.PushBack(10)
14
-	ptr := mylist.head
15
-	for ptr != nil {
16
-		fmt.Printf("data = %d, address = %p\n", ptr.val, ptr.next)
17
-		ptr = ptr.next
18
-	}
19
-}
20
-
21
-func Test_simpleLList_mergeSort(t *testing.T) {
22
-	mylist := new(LList)
23
-	mylist.PushBack(30)
24
-	mylist.PushBack(40)
25
-	mylist.PushBack(20)
26
-	mylist.PushBack(10)
27
-	mylist.head = MergeSort(mylist.head, mylist.size / 2)
28
-	ptr := mylist.head
29
-	for ptr != nil {
30
-		fmt.Printf("data = %d, address = %p\n", ptr.val, ptr.next)
31
-		ptr = ptr.next
32
-	}
33
-}
34
-
35
-func Test_removeArray(t *testing.T){}
36
-func Test_deleteList(t *testing.T){}
37
-func Test_insertList(t *testing.T){}

+ 2
- 1
modules/message.go Zobrazit soubor

@@ -71,7 +71,8 @@ type PublishMsg struct {
71 71
 type SubscriptionMsg struct {
72 72
 	Message
73 73
 	topic []int64 //대주제
74
-	value []string //범위 및 세부조건, 피연산자 연산자 순으로 등장
74
+	value []int64 //피연산자
75
+	operator []string //연산자
75 76
 	isAlpha bool // 범위연산인지 단순비교연산인지 구분 가능하게 함
76 77
 }
77 78
 

+ 49
- 8
modules/secure.go Zobrazit soubor

@@ -10,10 +10,18 @@ type Security struct{
10 10
 	KeyMap map[string] string
11 11
 }
12 12
 
13
-type SecurityManage interface {
14
-	reEncrypt()
15
-	keyGenPrivate()
16
-	compare()
13
+func NewSecurity() *Security{
14
+	security := &Security{map[string] string{}}
15
+	return security
16
+}
17
+
18
+type SecurityManager interface {
19
+	RegKey(ksm KeyShareMsg)
20
+	GetNodeKey(message Message) int64
21
+	ReEncrypt(fromKey int64,  toKey int64, target []int64) []int64
22
+	CompareTopic(topic1 []int64, topic2 []int64) int
23
+	CompareDigit(topic1 int64, topic2 int64) int
24
+	CompareAlpha(topic1 []int64, topic2 []int64) int
17 25
 }
18 26
 
19 27
 /**
@@ -26,12 +34,12 @@ func (sc Security) RegKey(ksm KeyShareMsg) {
26 34
 /**
27 35
 각 노드의 키를 주소를 이용하여 맵에서 가져옴
28 36
  */
29
-func (sc Security) GetNodeKey(message Message) int{
37
+func (sc Security) GetNodeKey(message Message) int64{
30 38
 
31 39
 	messageStringKey := sc.KeyMap[message.From()]
32
-	mKey, err := strconv.Atoi(messageStringKey)
40
+	mKey, err := strconv.ParseInt(messageStringKey, 10,64)
33 41
 	if err != nil {
34
-		fmt.Println("reEncrypt Error: key string to int error.")
42
+		fmt.Println("reEncrypt Error: key string to int64 parsing error.")
35 43
 	}
36 44
 	return mKey
37 45
 }
@@ -39,7 +47,7 @@ func (sc Security) GetNodeKey(message Message) int{
39 47
 /**
40 48
 reEncrypt 해서 슬라이스 반환
41 49
  */
42
-func (sc Security) ReEncrypt(fromKey int,  toKey int, target []int) []int{
50
+func (sc Security) ReEncrypt(fromKey int64,  toKey int64, target []int64) []int64{
43 51
 	for index := range target {
44 52
 		target[index] = target[index] - fromKey + toKey
45 53
 	}
@@ -48,6 +56,39 @@ func (sc Security) ReEncrypt(fromKey int,  toKey int, target []int) []int{
48 56
 }
49 57
 
50 58
 
59
+/**
60
+Compare 함수들은 같으면 0 다르면 -1 (비교가 필요한 경우 오름차순 1 내림차순 -1)
61
+ */
62
+func (sc Security) CompareTopic(topic1 []int64, topic2 []int64) int {
63
+	for i := 0; i< len(topic2); i++ {
64
+		if topic1[i] != topic2[i] {
65
+			return -1
66
+		}
67
+	}
68
+	return 0
69
+}
70
+
71
+func (sc Security) CompareDigit(topic1 int64, topic2 int64) int {
72
+	if topic1 < topic2 {
73
+		return 1
74
+	} else if topic1 > topic2 {
75
+		return -1
76
+	}
77
+	return 0
78
+}
79
+
80
+func (sc Security) CompareAlpha(topic1 []int64, topic2 []int64) int {
81
+	for i := 0; i< len(topic2); i++ {
82
+		if topic1[i] != topic2[i] {
83
+			return -1
84
+		}
85
+	}
86
+	return 0
87
+}
88
+
89
+
90
+
91
+
51 92
 // private key 생성 메세지
52 93
 //func (sc Security) keyGenPrivate() KeyGenMsg{
53 94
 //

Načítá se…
Zrušit
Uložit