1 package org.eclipse.aether.util.repository;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Map;
23 import java.util.Objects;
24
25 import static java.util.Objects.requireNonNull;
26
27 import org.eclipse.aether.repository.Authentication;
28 import org.eclipse.aether.repository.AuthenticationContext;
29 import org.eclipse.aether.repository.AuthenticationDigest;
30
31
32
33
34 final class StringAuthentication
35 implements Authentication
36 {
37
38 private final String key;
39
40 private final String value;
41
42 StringAuthentication( String key, String value )
43 {
44 this.key = requireNonNull( key, "authentication key cannot be null" );
45 if ( key.length() == 0 )
46 {
47 throw new IllegalArgumentException( "authentication key cannot be empty" );
48 }
49 this.value = value;
50 }
51
52 public void fill( AuthenticationContext context, String key, Map<String, String> data )
53 {
54 context.put( this.key, value );
55 }
56
57 public void digest( AuthenticationDigest digest )
58 {
59 digest.update( key, value );
60 }
61
62 @Override
63 public boolean equals( Object obj )
64 {
65 if ( this == obj )
66 {
67 return true;
68 }
69 if ( obj == null || !getClass().equals( obj.getClass() ) )
70 {
71 return false;
72 }
73 StringAuthentication that = (StringAuthentication) obj;
74 return Objects.equals( key, that.key )
75 && Objects.equals( value, that.value );
76 }
77
78 @Override
79 public int hashCode()
80 {
81 int hash = 17;
82 hash = hash * 31 + key.hashCode();
83 hash = hash * 31 + ( ( value != null ) ? value.hashCode() : 0 );
84 return hash;
85 }
86
87 @Override
88 public String toString()
89 {
90 return key + "=" + value;
91 }
92
93 }