1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.ssl;
17
18 import io.netty.buffer.ByteBuf;
19 import io.netty.buffer.ByteBufAllocator;
20 import io.netty.util.AbstractReferenceCounted;
21 import io.netty.util.IllegalReferenceCountException;
22 import io.netty.util.internal.ObjectUtil;
23
24
25
26
27
28
29
30
31 class PemValue extends AbstractReferenceCounted implements PemEncoded {
32
33 private final ByteBuf content;
34
35 private final boolean sensitive;
36
37 PemValue(ByteBuf content, boolean sensitive) {
38 this.content = ObjectUtil.checkNotNull(content, "content");
39 this.sensitive = sensitive;
40 }
41
42 @Override
43 public boolean isSensitive() {
44 return sensitive;
45 }
46
47 @Override
48 public ByteBuf content() {
49 int count = refCnt();
50 if (count <= 0) {
51 throw new IllegalReferenceCountException(count);
52 }
53
54 return content;
55 }
56
57 @Override
58 public PemValue copy() {
59 return replace(content.copy());
60 }
61
62 @Override
63 public PemValue duplicate() {
64 return replace(content.duplicate());
65 }
66
67 @Override
68 public PemValue retainedDuplicate() {
69 return replace(content.retainedDuplicate());
70 }
71
72 @Override
73 public PemValue replace(ByteBuf content) {
74 return new PemValue(content, sensitive);
75 }
76
77 @Override
78 public PemValue touch() {
79 return (PemValue) super.touch();
80 }
81
82 @Override
83 public PemValue touch(Object hint) {
84 content.touch(hint);
85 return this;
86 }
87
88 @Override
89 public PemValue retain() {
90 return (PemValue) super.retain();
91 }
92
93 @Override
94 public PemValue retain(int increment) {
95 return (PemValue) super.retain(increment);
96 }
97
98 @Override
99 protected void deallocate() {
100 if (sensitive) {
101 SslUtils.zeroout(content);
102 }
103 content.release();
104 }
105 }